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

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

commit f1033082f9b6199ce9ba216501a40dc883c3a068
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Aug 2 19:05:33 2026 +0200

    netutils/dropbear, testing/nand_sim: do not use fork() to run in background.
    
    Neither of these wants fork() semantics.  Both reach for fork() only to put
    work in the background, and each has a NuttX-native way to do that, so
    neither needs a fork primitive at all -- which matters once 
apache/nuttx#19562
    makes ARCH_HAVE_FORK conditional on the architecture implementing POSIX
    fork().
    
    netutils/dropbear: the port already routes every fork-then-exec through
    vfork(), because sysoptions.h selects DROPBEAR_VFORK when HAVE_FORK is
    undefined and the port leaves it undefined.  spawn_command() in dbutil.c and
    both call sites in scp.c follow that switch.  The one exception is the
    daemon() fallback that compat.c compiles under #ifndef HAVE_DAEMON, which
    calls fork() directly and bypasses it.  NuttX provides daemon() in
    libs/libc/unistd/lib_daemon.c and declares it in unistd.h, so the fallback 
is
    redundant; define HAVE_DAEMON alongside the HAVE_STRLCAT and HAVE_STRLCPY
    entries that are there for exactly the same reason.  The code was 
unreachable
    in any case -- the port hands svr_getopts() an argv containing -F, so
    svr_opts.forkbg is always zero and dropbear never calls daemon() at all.
    
    testing/drivers/nand_sim: forked so that the parent could return to the 
shell
    while the child registered the MTD device and slept forever.  Nothing from
    before the fork is used after it, so the child is a self-contained entry
    point, and task_create() expresses that directly.  The emulator body moves
    into nand_sim_daemon() unchanged.  TESTING_NAND_SIM therefore needs no fork
    dependency, and the two sim configurations that enable it keep working
    whatever ARCH_HAVE_FORK is set to.
    
    Assisted-by: Claude Opus 5 (1M context) <[email protected]>
    Signed-off-by: Marco Casaroli <[email protected]>
---
 netutils/dropbear/port/nuttx_config.h    |  1 +
 testing/drivers/nand_sim/nand_sim_main.c | 43 +++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/netutils/dropbear/port/nuttx_config.h 
b/netutils/dropbear/port/nuttx_config.h
index d91709d1e..6ab83fd17 100644
--- a/netutils/dropbear/port/nuttx_config.h
+++ b/netutils/dropbear/port/nuttx_config.h
@@ -48,6 +48,7 @@
 #define HAVE_CLOCK_GETTIME 1
 #define HAVE_CONST_GAI_STRERROR_PROTO 1
 #define HAVE_CRYPT 1
+#define HAVE_DAEMON 1
 #define HAVE_DECL_HTOLE64 1
 #define HAVE_ENDIAN_H 1
 #define HAVE_EXPLICIT_BZERO 1
diff --git a/testing/drivers/nand_sim/nand_sim_main.c 
b/testing/drivers/nand_sim/nand_sim_main.c
index 70ea24227..48ee969e5 100644
--- a/testing/drivers/nand_sim/nand_sim_main.c
+++ b/testing/drivers/nand_sim/nand_sim_main.c
@@ -25,6 +25,7 @@
  ****************************************************************************/
 
 #include <nuttx/debug.h>
+#include <sched.h>
 #include <stdio.h>
 
 #include <nuttx/drivers/drivers.h>
@@ -128,26 +129,17 @@ void terminate(int sig)
 }
 
 /****************************************************************************
- * Name: nand_sim_main
+ * Name: nand_sim_daemon
  *
  * Description:
- *   Entry point of the device emulator.
+ *   Body of the device emulator.  Registers the simulated MTD device and
+ *   then sleeps forever; all events are handled by signals.
  *
  ****************************************************************************/
 
-int main(int argc, FAR char *argv[])
+static int nand_sim_daemon(int argc, FAR char *argv[])
 {
-  int   ret;
-  pid_t pid;
-
-  /* Daemon */
-
-  pid = fork();
-
-  if (pid > 0)
-    {
-      return OK;
-    }
+  int ret;
 
   if (daemon(0, 1) == -1)
     {
@@ -223,3 +215,26 @@ errout_with_logs:
 errout:
   return ret;
 }
+
+/****************************************************************************
+ * Name: nand_sim_main
+ *
+ * Description:
+ *   Entry point of the device emulator.  Starts the emulator as an
+ *   independent task so that the caller gets its shell back.
+ *
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  int ret;
+
+  ret = task_create(NAND_SIM_NAME, SCHED_PRIORITY_DEFAULT,
+                    CONFIG_TESTING_NAND_SIM_STACK, nand_sim_daemon, NULL);
+  if (ret < 0)
+    {
+      return EXIT_FAILURE;
+    }
+
+  return OK;
+}

Reply via email to