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