[rtems commit] telnetd: Allocate the server context

Sebastian Huber sebh at rtems.org
Thu Oct 11 07:11:40 UTC 2018


Module:    rtems
Branch:    master
Commit:    0f0e130051cd4aba49885681c60ff226927e143e
Changeset: http://git.rtems.org/rtems/commit/?id=0f0e130051cd4aba49885681c60ff226927e143e

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Oct 10 09:11:47 2018 +0200

telnetd: Allocate the server context

Update #3543.

---

 cpukit/telnetd/telnetd.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 0fd3b31..aadf33d 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -81,9 +81,6 @@ typedef union uni_sa {
   struct sockaddr     sa;
 } uni_sa;
 
-/***********************************************************/
-static telnetd_context telnetd_instance;
-
 static telnetd_session *grab_a_Connection(telnetd_context *ctx)
 {
   telnetd_session *session;
@@ -245,6 +242,8 @@ static void telnetd_destroy_context(telnetd_context *ctx)
   if (ctx->server_socket >= 0) {
     close(ctx->server_socket);
   }
+
+  free(ctx);
 }
 
 static rtems_status_code telnetd_create_server_socket(telnetd_context *ctx)
@@ -288,7 +287,7 @@ static rtems_status_code telnetd_create_server_socket(telnetd_context *ctx)
 
 rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
 {
-  telnetd_context *ctx = &telnetd_instance;
+  telnetd_context *ctx;
   rtems_id task_id;
   rtems_status_code sc;
 
@@ -297,12 +296,14 @@ rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
     return RTEMS_INVALID_ADDRESS;
   }
 
-  if (ctx->config.command != NULL) {
-    syslog(LOG_DAEMON | LOG_ERR, "telnetd: already started");
-    return RTEMS_RESOURCE_IN_USE;
+  ctx = calloc(1, sizeof(*ctx));
+  if (ctx == NULL) {
+    syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot allocate server context");
+    return RTEMS_UNSATISFIED;
   }
 
   ctx->config = *config;
+  ctx->server_socket = -1;
 
   /* Check priority */
 #ifdef RTEMS_NETWORKING



More information about the vc mailing list