Skip to content

Commit b636a88

Browse files
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]>
1 parent e5bf043 commit b636a88

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

system/nxinit/service.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static int option_restart_period(FAR struct service_manager_s *sm,
9797
int argc, FAR char **argv);
9898
static int option_override(FAR struct service_manager_s *sm,
9999
int argc, FAR char **argv);
100+
static int option_oneshot(FAR struct service_manager_s *sm,
101+
int argc, FAR char **argv);
100102

101103
/****************************************************************************
102104
* Private Data
@@ -108,6 +110,7 @@ static const struct cmd_map_s g_option[] =
108110
{"gentle_kill", 1, 1, option_gentle_kill},
109111
{"restart_period", 2, 2, option_restart_period},
110112
{"override", 1, 1, option_override},
113+
{"oneshot", 1, 1, option_oneshot},
111114
};
112115

113116
#ifdef CONFIG_SYSTEM_NXINIT_DEBUG
@@ -248,6 +251,16 @@ static int option_override(FAR struct service_manager_s *sm,
248251
return 0;
249252
}
250253

254+
static int option_oneshot(FAR struct service_manager_s *sm,
255+
int argc, FAR char **argv)
256+
{
257+
FAR struct service_s *s = list_last_entry(&sm->services, struct service_s,
258+
node);
259+
260+
add_flags(s, SVC_ONESHOT);
261+
return 0;
262+
}
263+
251264
/****************************************************************************
252265
* Public Functions
253266
****************************************************************************/
@@ -361,6 +374,11 @@ init_service_find_by_pid(FAR struct service_manager_s *sm, const int pid)
361374
void init_service_reap(FAR struct service_s *service)
362375
{
363376
remove_flags(service, SVC_RUNNING);
377+
if (check_flags(service, SVC_ONESHOT))
378+
{
379+
add_flags(service, SVC_DISABLED | SVC_REMOVE);
380+
}
381+
364382
if (!check_flags(service, SVC_DISABLED))
365383
{
366384
add_flags(service, SVC_RESTARTING);

0 commit comments

Comments
 (0)