You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/03 13:17:31 UTC

[incubator-nuttx-apps] 01/06: Remove the global variable in telnetd_daemon

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr45
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 28891ef27e841d4a6f8b1a12f268f1261e8d78ee
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Feb 3 16:54:54 2020 +0800

    Remove the global variable in telnetd_daemon
    
    Change-Id: I264d10c0f141109ada6ac90afb2ba3e8cfad4404
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 netutils/telnetd/telnetd_daemon.c | 66 ++++++---------------------------------
 1 file changed, 10 insertions(+), 56 deletions(-)

diff --git a/netutils/telnetd/telnetd_daemon.c b/netutils/telnetd/telnetd_daemon.c
index 1effb3b..1ba9ce8 100644
--- a/netutils/telnetd/telnetd_daemon.c
+++ b/netutils/telnetd/telnetd_daemon.c
@@ -43,6 +43,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 
+#include <inttypes.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -81,31 +82,6 @@ struct telnetd_s
                                     * connection is accepted. */
 };
 
-/* This structure is used to passed information to telnet daemon when it
- * started.  It contains global information visable to all telnet daemons.
- */
-
-struct telnetd_common_s
-{
-  uint8_t               ndaemons;  /* The total number of daemons running */
-  sem_t                 startsem;  /* Enforces one-at-a-time startup */
-  FAR struct telnetd_s *daemon;    /* Describes the new daemon */
-};
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/* This structure is used to passed information to telnet daemon when it
- * started.
- */
-
-static struct telnetd_common_s g_telnetdcommon;
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -125,7 +101,7 @@ static struct telnetd_common_s g_telnetdcommon;
  *
  ****************************************************************************/
 
-static int telnetd_daemon(int argc, char *argv[])
+static int telnetd_daemon(int argc, FAR char *argv[])
 {
   FAR struct telnetd_s *daemon;
   union
@@ -159,9 +135,7 @@ static int telnetd_daemon(int argc, char *argv[])
 
   /* Get daemon startup info */
 
-  daemon = g_telnetdcommon.daemon;
-  g_telnetdcommon.daemon = NULL;
-  sem_post(&g_telnetdcommon.startsem);
+  daemon = (FAR struct telnetd_s *)((uintptr_t)strtoul(argv[1], NULL, 0));
   DEBUGASSERT(daemon != NULL);
 
 #ifdef CONFIG_SCHED_HAVE_PARENT
@@ -412,8 +386,9 @@ errout_with_socket:
 int telnetd_start(FAR struct telnetd_config_s *config)
 {
   FAR struct telnetd_s *daemon;
+  FAR char *argv[2];
+  char arg0[16];
   pid_t pid;
-  int ret;
 
   /* Allocate a state structure for the new daemon */
 
@@ -431,18 +406,14 @@ int telnetd_start(FAR struct telnetd_config_s *config)
   daemon->stacksize = config->t_stacksize;
   daemon->entry     = config->t_entry;
 
-  /* Initialize the common structure if this is the first daemon */
-
-  if (g_telnetdcommon.ndaemons < 1)
-    {
-      sem_init(&g_telnetdcommon.startsem, 0, 0);
-    }
-
   /* Then start the new daemon */
 
-  g_telnetdcommon.daemon = daemon;
+  snprintf(arg0, 16, "0x%" PRIxPTR, (uintptr_t)daemon);
+  argv[0] = arg0;
+  argv[1] = NULL;
+
   pid = task_create("Telnet daemon", config->d_priority, config->d_stacksize,
-                    telnetd_daemon, NULL);
+                    telnetd_daemon, argv);
   if (pid < 0)
     {
       int errval = errno;
@@ -451,23 +422,6 @@ int telnetd_start(FAR struct telnetd_config_s *config)
       return -errval;
     }
 
-  /* Then wait for the daemon to start and complete the handshake */
-
-  do
-    {
-      ret = sem_wait(&g_telnetdcommon.startsem);
-
-      /* The only expected error condition is for sem_wait to be awakened by
-       * a receipt of a signal.
-       */
-
-      if (ret < 0)
-        {
-          DEBUGASSERT(errno == EINTR || errno  == ECANCELED);
-        }
-    }
-  while (ret < 0);
-
   /* Return success */
 
   return pid;