Fix #274: allow manual:yes on sysv/service/run/task

Prior to this change only service stanzas respected the manual:yes
option, now it (should) work on any svc_t type.  Not tested on ttys.

The initctl tool has been given an extra manual=yes output for these
types of run/task/service entries, shown only when the manual option
is set.

Example:

root@anarchy:~# initctl status foo.sh
     Status : stopped (code=exited, status=0/SUCCESS, manual=yes)
   Identity : foo.sh                                ~~~~~~~~~~~~
Description : Hej foo
     Origin : /etc/finit.d/enabled/foo.conf
Environment :
Condition(s):
    Command : /root/foo.sh
   PID file : none
        PID : 0
       User : root
      Group : root
     Uptime : N/A
     Starts : 1
   Restarts : 0 (0/10)
  Runlevels : [--2345----]

Notice also the new `Starts : 1` which is a counter for the number of
starts in the current runlevel.  On runlevel change it is reset to 0.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-06-16 17:57:55 +02:00
1 parent 6de67ed107
commit 5f908cae49
3 files changed
+21 -12

No files matched your search

+7 -2
View File
@@ -1374,7 +1374,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
return errno = ENOMEM;
}
if (type == SVC_TYPE_SERVICE && manual)
if (manual)
svc_stop(svc);
} else {
_d("Found existing svc for %s name %s id %s type %d", cmd, name, id, type);
@@ -1463,6 +1463,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
parse_env(svc, env);
if (file)
strlcpy(svc->file, file, sizeof(svc->file));
svc->manual = manual;
svc->respawn = respawn;
svc->forking = forking;
svc->restart_max = restart_max;
@@ -1920,7 +1921,11 @@ restart:
case SVC_TYPE_TASK:
case SVC_TYPE_RUN:
svc_set_state(svc, SVC_DONE_STATE);
if (svc->manual) {
svc_stop(svc);
svc_set_state(svc, SVC_HALTED_STATE);
} else
svc_set_state(svc, SVC_DONE_STATE);
break;
default: