mirror of
https://github.com/troglobit/finit.git
synced 2026-10-09 16:50:59 +07:00
Refactor: Further API cleanup -- hide svc_t internals.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -183,7 +183,7 @@ int inetd_respawn(pid_t pid)
|
||||
|
||||
svc->pid = 0;
|
||||
|
||||
if (ISSET(svc->runlevels, runlevel) && !inetd->forking)
|
||||
if (svc_in_runlevel(svc, runlevel) && !inetd->forking)
|
||||
uev_io_set(&inetd->watcher, inetd->watcher.fd, UEV_READ);
|
||||
|
||||
return 1; /* It was us! */
|
||||
|
||||
@@ -91,7 +91,7 @@ svc_cmd_t service_enabled(svc_t *svc, int event, void *arg)
|
||||
return SVC_STOP;
|
||||
}
|
||||
|
||||
if (!ISSET(svc->runlevels, runlevel))
|
||||
if (!svc_in_runlevel(svc, runlevel))
|
||||
return SVC_STOP;
|
||||
|
||||
/* Is there a service plugin registered? */
|
||||
@@ -335,7 +335,7 @@ exit:
|
||||
}
|
||||
|
||||
/**
|
||||
* service_start_dynamic - Start or reload modified dynamic services
|
||||
* service_start_dynamic - Start new or reload modified dynamic services
|
||||
*/
|
||||
void service_start_dynamic(void)
|
||||
{
|
||||
@@ -343,7 +343,7 @@ void service_start_dynamic(void)
|
||||
|
||||
_d("Starting enabled/added services ...");
|
||||
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
||||
if (svc->dirty > 0)
|
||||
if (svc_is_updated(svc))
|
||||
svc_dance(svc);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ void service_stop_dynamic(void)
|
||||
|
||||
_d("Stopping disabled/removed services ...");
|
||||
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
||||
if (svc->dirty != 0)
|
||||
if (svc_is_changed(svc))
|
||||
service_stop(svc);
|
||||
}
|
||||
}
|
||||
@@ -461,7 +461,7 @@ void service_runlevel(int newlevel)
|
||||
|
||||
_d("Stopping services services not allowed in new runlevel ...");
|
||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||
if (!ISSET(svc->runlevels, runlevel)) {
|
||||
if (!svc_in_runlevel(svc, runlevel)) {
|
||||
#ifndef INETD_DISABLED
|
||||
if (svc_is_inetd(svc))
|
||||
inetd_stop(&svc->inetd);
|
||||
@@ -471,7 +471,7 @@ void service_runlevel(int newlevel)
|
||||
}
|
||||
|
||||
/* ... or disabled/removed services from /etc/finit.d/ */
|
||||
if (svc->mtime && svc->dirty != 0)
|
||||
if (svc_is_dynamic(svc) && svc_is_changed(svc))
|
||||
service_stop(svc);
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ void service_runlevel(int newlevel)
|
||||
#ifndef INETD_DISABLED
|
||||
/* Inetd services have slightly different semantics */
|
||||
if (svc_is_inetd(svc)) {
|
||||
if (ISSET(svc->runlevels, runlevel))
|
||||
if (svc_in_runlevel(svc, runlevel))
|
||||
inetd_start(&svc->inetd);
|
||||
|
||||
continue;
|
||||
|
||||
@@ -364,7 +364,7 @@ char *svc_status(svc_t *svc)
|
||||
if (svc->pid)
|
||||
return "running";
|
||||
|
||||
if (!ISSET(svc->runlevels, runlevel))
|
||||
if (!svc_in_runlevel(svc, runlevel))
|
||||
return "halted";
|
||||
|
||||
if (svc_is_inetd(svc))
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <sys/types.h> /* pid_t */
|
||||
|
||||
#include "inetd.h"
|
||||
#include "helpers.h"
|
||||
|
||||
typedef enum {
|
||||
SVC_STOP = 0, /* Disabled */
|
||||
@@ -135,8 +136,15 @@ char *svc_status (svc_t *svc);
|
||||
int svc_next_id (char *cmd);
|
||||
int svc_is_unique (svc_t *svc);
|
||||
|
||||
static inline int svc_is_inetd (svc_t *svc) { return svc && SVC_TYPE_INETD == svc->type; }
|
||||
static inline int svc_is_daemon(svc_t *svc) { return svc && SVC_TYPE_SERVICE == svc->type; }
|
||||
static inline int svc_in_runlevel(svc_t *svc, int runlevel) { return svc && ISSET(svc->runlevels, runlevel); }
|
||||
|
||||
static inline int svc_is_dynamic(svc_t *svc) { return svc && 0 != svc->mtime; }
|
||||
static inline int svc_is_removed(svc_t *svc) { return svc && -1 == svc->dirty; }
|
||||
static inline int svc_is_changed(svc_t *svc) { return svc && 0 != svc->dirty; }
|
||||
static inline int svc_is_updated(svc_t *svc) { return svc && 1 == svc->dirty; }
|
||||
|
||||
static inline int svc_is_inetd (svc_t *svc) { return svc && SVC_TYPE_INETD == svc->type; }
|
||||
static inline int svc_is_daemon (svc_t *svc) { return svc && SVC_TYPE_SERVICE == svc->type; }
|
||||
|
||||
#endif /* FINIT_SVC_H_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user