Refactor abstraction of svc blocking state

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-09-12 19:30:48 +02:00
parent b4f385d2e0
commit 6b237b7b00
4 changed files with 27 additions and 15 deletions
+4 -2
View File
@@ -115,15 +115,17 @@ static int call(int (*action)(svc_t *), char *buf, size_t len)
static int service_block(svc_t *svc)
{
svc->block = SVC_BLOCK_USER;
svc_block(svc);
service_step(svc);
return 0;
}
static int service_unblock(svc_t *svc)
{
svc->block = SVC_BLOCK_NONE;
svc_unblock(svc);
service_step(svc);
return 0;
}
+3 -3
View File
@@ -166,7 +166,7 @@ static void socket_cb(uev_t *UNUSED(w), void *arg, int UNUSED(events))
}
if (!svc->inetd.forking) {
svc->block = SVC_BLOCK_INETD_BUSY;
svc_busy(svc);
service_step(svc);
}
@@ -311,7 +311,7 @@ void inetd_stop(inetd_t *inetd)
/* For dgram inetd services we block the parent SVC
* and halt the watcher, so don't close the socket! */
if (inetd->svc->block != SVC_BLOCK_INETD_BUSY) {
if (!svc_is_busy(inetd->svc)) {
_d("Shutting down inet socket %d ...", inetd->watcher.fd);
if (inetd->type == SOCK_STREAM)
shutdown(inetd->watcher.fd, SHUT_RDWR);
@@ -684,7 +684,7 @@ int inetd_new(inetd_t *inetd, char *name, char *service, char *proto, int forkin
int inetd_del(inetd_t *inetd)
{
inetd->svc->block = 0;
svc_unblock(inetd->svc);
inetd_stop(inetd);
return inetd_flush(inetd);
+12 -10
View File
@@ -58,10 +58,13 @@ static svc_t *find_inetd_svc (char *path, char *service, char *proto);
*/
int service_enabled(svc_t *svc)
{
if (!svc ||
!svc_in_runlevel(svc, runlevel) ||
svc_is_removed(svc) ||
svc->block != SVC_BLOCK_NONE)
if (!svc)
return 0;
if (!svc_in_runlevel(svc, runlevel))
return 0;
if (svc_is_removed(svc) || svc_is_blocked(svc))
return 0;
return 1;
@@ -117,7 +120,7 @@ static int service_start(svc_t *svc)
print_result(1);
}
svc->block = SVC_BLOCK_MISSING;
svc_missing(svc);
return 1;
}
@@ -309,8 +312,7 @@ static int service_stop(svc_t *svc)
#ifndef INETD_DISABLED
if (svc_is_inetd(svc)) {
int do_print = runlevel != 1 && !silent &&
svc->block != SVC_BLOCK_INETD_BUSY;
int do_print = runlevel != 1 && !silent && !svc_is_busy(svc);
if (do_print)
print_desc("Stopping ", svc->desc);
@@ -733,8 +735,8 @@ restart:
case SVC_DONE_STATE:
#ifndef INETD_DISABLED
if (svc_is_inetd_conn(svc)) {
if (svc->inetd.svc->block == SVC_BLOCK_INETD_BUSY) {
svc->inetd.svc->block = 0;
if (svc_is_busy(svc)) {
svc_unblock(svc->inetd.svc);
service_step(svc->inetd.svc);
}
service_unregister(svc);
@@ -772,7 +774,7 @@ restart:
} else if (cond_get_agg(svc->cond) == COND_ON) {
if (*restart_counter >= RESPAWN_MAX) {
_e("%s keeps crashing, not restarting", svc->desc);
svc->block = SVC_BLOCK_CRASHING;
svc_crashing(svc);
svc_set_state(svc, SVC_HALTED_STATE);
break;
}
+8
View File
@@ -187,6 +187,14 @@ static inline int svc_is_inetd (svc_t *svc) { return svc && SVC_TYPE_INETD
static inline int svc_is_inetd_conn(svc_t *svc) { return svc && SVC_TYPE_INETD_CONN == svc->type; }
static inline int svc_is_daemon (svc_t *svc) { return svc && SVC_TYPE_SERVICE == svc->type; }
static inline int svc_is_blocked (svc_t *svc) { return svc->block != SVC_BLOCK_NONE; }
static inline int svc_is_busy (svc_t *svc) { return svc->block == SVC_BLOCK_INETD_BUSY; }
static inline void svc_unblock (svc_t *svc) { svc->block = SVC_BLOCK_NONE; }
static inline void svc_block (svc_t *svc) { svc->block = SVC_BLOCK_USER; }
static inline void svc_busy (svc_t *svc) { svc->block = SVC_BLOCK_INETD_BUSY; }
static inline void svc_missing (svc_t *svc) { svc->block = SVC_BLOCK_MISSING; }
static inline void svc_crashing (svc_t *svc) { svc->block = SVC_BLOCK_CRASHING; }
#endif /* FINIT_SVC_H_ */
/**