mirror of
https://github.com/troglobit/finit.git
synced 2026-10-27 12:20:54 +00:00
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:
2 files changed
+11
-10
No files matched your search
+9
-9
@@ -670,7 +670,7 @@ static int service_start(svc_t *svc)
|
|||||||
do_progress = 0;
|
do_progress = 0;
|
||||||
|
|
||||||
if (do_progress) {
|
if (do_progress) {
|
||||||
if (svc_is_daemon(svc) || svc_is_sysv(svc))
|
if (svc_is_daemon(svc))
|
||||||
print_desc("Starting ", svc->desc);
|
print_desc("Starting ", svc->desc);
|
||||||
else
|
else
|
||||||
print_desc("", svc->desc);
|
print_desc("", svc->desc);
|
||||||
@@ -680,7 +680,7 @@ static int service_start(svc_t *svc)
|
|||||||
svc_starting(svc);
|
svc_starting(svc);
|
||||||
|
|
||||||
/* Increment total restarts, unless first time or non-service */
|
/* 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)
|
if (svc->restart_cnt || svc->restart_tot)
|
||||||
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
|
* Skip run/tasks in progress, would otherwise print silly stuff
|
||||||
* like: "Stopping Shutting down" ...
|
* 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);
|
print_desc("Stopping ", svc->desc);
|
||||||
|
|
||||||
if (!svc_is_sysv(svc)) {
|
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);
|
print_result(rc);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@@ -1969,7 +1969,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
svc->oncrash_action = oncrash_action;
|
svc->oncrash_action = oncrash_action;
|
||||||
|
|
||||||
/* Decode any (optional) pid:/optional/path/to/file.pid */
|
/* 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 */
|
char tmp[sizeof(svc->name) + 6]; /* pid:! + svc->name */
|
||||||
|
|
||||||
/* no pid: set, figure out a default to track this svc */
|
/* 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);
|
kill(-svc->pid, SIGKILL);
|
||||||
|
|
||||||
/* Try removing PID file (in case service does not clean up after itself) */
|
/* 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);
|
service_cleanup(svc);
|
||||||
} else if (svc_is_runtask(svc)) {
|
} else if (svc_is_runtask(svc)) {
|
||||||
/* run/task should run at least once per runlevel */
|
/* 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];
|
char cond[MAX_COND_LEN];
|
||||||
|
|
||||||
snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0));
|
snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0));
|
||||||
@@ -2766,7 +2766,7 @@ restart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!svc->pid) {
|
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_restarting(svc); /* BLOCK_RESTARTING */
|
||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
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)) {
|
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;
|
char *restart_cnt = (char *)&svc->restart_cnt;
|
||||||
|
|
||||||
if (!svc_is_running(svc))
|
if (!svc_is_running(svc))
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ typedef enum {
|
|||||||
} svc_type_t;
|
} svc_type_t;
|
||||||
|
|
||||||
#define SVC_TYPE_ANY (-1)
|
#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_RESPAWN (SVC_TYPE_SERVICE | SVC_TYPE_SYSV | SVC_TYPE_TTY)
|
||||||
#define SVC_TYPE_RUNTASK (SVC_TYPE_RUN | SVC_TYPE_TASK)
|
#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 *));
|
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_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_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);}
|
static inline int svc_is_runtask (svc_t *svc) { return svc && (SVC_TYPE_RUNTASK & svc->type);}
|
||||||
|
|||||||
Reference in new issue
Block a user