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 8049d91a951ca2a09be7222c4a5f78b19aab0531
Author: wangjianyu3 <[email protected]>
AuthorDate: Fri Oct 10 22:38:15 2025 +0800

    system/nxinit: Add oneshot support for service
    
    Add support for the oneshot option to the service.
    
    Test
      - RC
          service telnet telnetd
              class test
        >     oneshot
              restart_period 3000
      - Runtime
          [    0.150000] [ 3] [ 0] init_main: == Dump Services ==
          ...
          [    0.160000] [ 3] [ 0] init_main: Service 0x40486aa8 name 'telnet' 
path 'telnetd'
          [    0.160000] [ 3] [ 0] init_main:   pid: 0
          [    0.160000] [ 3] [ 0] init_main:   arguments:
          [    0.160000] [ 3] [ 0] init_main:       [0] 'service'
          [    0.160000] [ 3] [ 0] init_main:       [1] 'telnet'
          [    0.160000] [ 3] [ 0] init_main:       [2] 'telnetd'
          [    0.160000] [ 3] [ 0] init_main:   classes:
          [    0.160000] [ 3] [ 0] init_main:     'test'
          [    0.170000] [ 3] [ 0] init_main:   restart_period: 3000
          [    0.170000] [ 3] [ 0] init_main:   reboot_on_failure: -1
          [    0.170000] [ 3] [ 0] init_main:   flags:
        > [    0.170000] [ 3] [ 0] init_main:     'oneshot'
          ...
          [    0.370000] [ 3] [ 0] init_main: starting service 'telnet' ...
          [    0.380000] [ 3] [ 0] init_main: service 'telnet' flag 0x2 add 0x4
          [    0.380000] [ 3] [ 0] init_main:   +flag 'running'
          [    0.380000] [ 3] [ 0] init_main: service 'telnet' flag 0x6 add 0x8
          [    0.380000] [ 3] [ 0] init_main:   -flag 'restarting'
          [    0.380000] [ 3] [ 0] init_main: service 'telnet' flag 0x6 add 0x1
          [    0.380000] [ 3] [ 0] init_main:   -flag 'disabled'
          [    0.380000] [ 3] [ 0] init_main: started service 'telnet' pid 9
          ...
          nsh> kill -9 9
          nsh> [    7.350000] [ 3] [ 0] init_main: service 'telnet' flag 0x6 
add 0x4
          [    7.350000] [ 3] [ 0] init_main:   -flag 'running'
          [    7.350000] [ 3] [ 0] init_main: service 'telnet' flag 0x2 add 
0x80000001
          [    7.350000] [ 3] [ 0] init_main:   +flag 'disabled'
          [    7.350000] [ 3] [ 0] init_main:   +flag 'remove'
          [    7.350000] [ 3] [ 0] init_main: service 'telnet' pid 9 exited 
status 1
        > [    7.360000] [ 3] [ 0] init_main: removing service 'telnet' ...
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 system/nxinit/service.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/system/nxinit/service.c b/system/nxinit/service.c
index 6916dd419..8f456c920 100644
--- a/system/nxinit/service.c
+++ b/system/nxinit/service.c
@@ -97,6 +97,8 @@ static int option_restart_period(FAR struct service_manager_s 
*sm,
                                  int argc, FAR char **argv);
 static int option_override(FAR struct service_manager_s *sm,
                            int argc, FAR char **argv);
+static int option_oneshot(FAR struct service_manager_s *sm,
+                          int argc, FAR char **argv);
 
 /****************************************************************************
  * Private Data
@@ -108,6 +110,7 @@ static const struct cmd_map_s g_option[] =
   {"gentle_kill", 1, 1, option_gentle_kill},
   {"restart_period", 2, 2, option_restart_period},
   {"override", 1, 1, option_override},
+  {"oneshot", 1, 1, option_oneshot},
 };
 
 #ifdef CONFIG_SYSTEM_NXINIT_DEBUG
@@ -248,6 +251,16 @@ static int option_override(FAR struct service_manager_s 
*sm,
   return 0;
 }
 
+static int option_oneshot(FAR struct service_manager_s *sm,
+                          int argc, FAR char **argv)
+{
+  FAR struct service_s *s = list_last_entry(&sm->services, struct service_s,
+                                            node);
+
+  add_flags(s, SVC_ONESHOT);
+  return 0;
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -361,6 +374,11 @@ init_service_find_by_pid(FAR struct service_manager_s *sm, 
const int pid)
 void init_service_reap(FAR struct service_s *service)
 {
   remove_flags(service, SVC_RUNNING);
+  if (check_flags(service, SVC_ONESHOT))
+    {
+      add_flags(service, SVC_DISABLED | SVC_REMOVE);
+    }
+
   if (!check_flags(service, SVC_DISABLED))
     {
       add_flags(service, SVC_RESTARTING);

Reply via email to