Simplify, a daemon is one of service or sysv

Historically we've kept these two apart, but their commonalities are far
more than what separates them.

This fixes a bug where ready:scripts were not called for sysv daemons,
and also opens up for adding support for a reload:script for both types.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-07-06 03:13:54 +02:00
parent dedb56a9d0
commit 39f4aa3f2c
2 changed files with 11 additions and 10 deletions
+9 -9
View File
@@ -670,7 +670,7 @@ static int service_start(svc_t *svc)
do_progress = 0;
if (do_progress) {
if (svc_is_daemon(svc) || svc_is_sysv(svc))
if (svc_is_daemon(svc))
print_desc("Starting ", svc->desc);
else
print_desc("", svc->desc);
@@ -680,7 +680,7 @@ static int service_start(svc_t *svc)
svc_starting(svc);
/* Increment total restarts, unless first time or non-service */
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
if (svc_is_daemon(svc)) {
if (svc->restart_cnt || svc->restart_tot)
svc->restart_tot++;
}
@@ -1057,7 +1057,7 @@ int service_stop(svc_t *svc)
* Skip run/tasks in progress, would otherwise print silly stuff
* like: "Stopping Shutting down" ...
*/
if (runlevel != 1 && do_progress && (svc_is_daemon(svc) || svc_is_sysv(svc)))
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
print_desc("Stopping ", svc->desc);
if (!svc_is_sysv(svc)) {
@@ -1113,7 +1113,7 @@ int service_stop(svc_t *svc)
}
}
if (runlevel != 1 && do_progress && (svc_is_daemon(svc) || svc_is_sysv(svc)))
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
print_result(rc);
return rc;
@@ -1969,7 +1969,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
svc->oncrash_action = oncrash_action;
/* Decode any (optional) pid:/optional/path/to/file.pid */
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
if (svc_is_daemon(svc)) {
char tmp[sizeof(svc->name) + 6]; /* pid:! + svc->name */
/* no pid: set, figure out a default to track this svc */
@@ -2109,7 +2109,7 @@ void service_monitor(pid_t lost, int status)
kill(-svc->pid, SIGKILL);
/* Try removing PID file (in case service does not clean up after itself) */
if (svc_is_daemon(svc) || svc_is_sysv(svc) || svc_is_tty(svc)) {
if (svc_is_daemon(svc) || svc_is_tty(svc)) {
service_cleanup(svc);
} else if (svc_is_runtask(svc)) {
/* run/task should run at least once per runlevel */
@@ -2510,7 +2510,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
}
}
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
if (svc_is_daemon(svc)) {
char cond[MAX_COND_LEN];
snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0));
@@ -2766,7 +2766,7 @@ restart:
}
if (!svc->pid) {
if (svc_is_daemon(svc) || svc_is_sysv(svc) || svc_is_tty(svc)) {
if (svc_is_daemon(svc) || svc_is_tty(svc)) {
svc_restarting(svc); /* BLOCK_RESTARTING */
svc_set_state(svc, SVC_HALTED_STATE);
@@ -3087,7 +3087,7 @@ static void service_interval_cb(uev_t *w, void *arg, int events)
}
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
if (svc_is_daemon(svc)) {
char *restart_cnt = (char *)&svc->restart_cnt;
if (!svc_is_running(svc))
+2 -1
View File
@@ -52,6 +52,7 @@ typedef enum {
} svc_type_t;
#define SVC_TYPE_ANY (-1)
#define SVC_TYPE_DAEMON (SVC_TYPE_SERVICE | SVC_TYPE_SYSV)
#define SVC_TYPE_RESPAWN (SVC_TYPE_SERVICE | SVC_TYPE_SYSV | SVC_TYPE_TTY)
#define SVC_TYPE_RUNTASK (SVC_TYPE_RUN | SVC_TYPE_TASK)
@@ -265,7 +266,7 @@ int svc_ifthen (int is_conf, const char *ident, char *stmt,
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
static inline int svc_is_daemon (svc_t *svc) { return svc && SVC_TYPE_SERVICE == svc->type; }
static inline int svc_is_daemon (svc_t *svc) { return svc && (SVC_TYPE_DAEMON & svc->type); }
static inline int svc_is_sysv (svc_t *svc) { return svc && SVC_TYPE_SYSV == svc->type; }
static inline int svc_is_tty (svc_t *svc) { return svc && SVC_TYPE_TTY == svc->type; }
static inline int svc_is_runtask (svc_t *svc) { return svc && (SVC_TYPE_RUNTASK & svc->type);}