From f95cd38ddb6461583f99e5c85219e2faa78b8b70 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 30 Dec 2016 13:32:19 +0100 Subject: [PATCH] Refactor #ifndef INETD_DISABLED --> #ifdef INETD_ENABLED This patch changes the confusing logic in all #ifndef INETD_DISABLED statements to instead be #ifdef INETD_ENABLED, which is quite a bit more readable. Signed-off-by: Joachim Nilsson --- api.c | 6 +++--- conf.c | 2 +- configure.ac | 6 +++--- initctl.c | 4 ++-- service.c | 22 +++++++++++----------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/api.c b/api.c index 2f16ad51..6be8175e 100644 --- a/api.c +++ b/api.c @@ -140,7 +140,7 @@ static int do_start (char *buf, size_t len) { return call(service_unblock, buf, static int do_pause (char *buf, size_t len) { return call(service_block, buf, len); } static int do_restart(char *buf, size_t len) { return call(service_restart, buf, len); } -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED static int do_query_inetd(char *buf, size_t len) { int id = 1; @@ -164,7 +164,7 @@ static int do_query_inetd(char *buf, size_t len) return inetd_filter_str(&svc->inetd, buf, len); } -#endif /* !INETD_DISABLED */ +#endif /* INETD_ENABLED */ typedef struct { char *event; @@ -305,7 +305,7 @@ static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events)) result = do_restart(rq.data, sizeof(rq.data)); break; -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED case INIT_CMD_QUERY_INETD: result = do_query_inetd(rq.data, sizeof(rq.data)); break; diff --git a/conf.c b/conf.c index ae7135e3..4c3839fa 100644 --- a/conf.c +++ b/conf.c @@ -360,7 +360,7 @@ static void parse_dynamic(char *line, time_t mtime) /* Classic inetd service */ if (MATCH_CMD(line, "inetd ", x)) { -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED service_register(SVC_TYPE_INETD, x, mtime, NULL); #else _e("Finit built with inetd support disabled, cannot register service inetd %s!", x); diff --git a/configure.ac b/configure.ac index 14b363c1..be981838 100644 --- a/configure.ac +++ b/configure.ac @@ -141,9 +141,9 @@ AS_IF([test "x$enable_watchdog" = "xyes"], [ AC_DEFINE(BUILTIN_WATCHDOG, 1, [Enable built-in watchdog, kicks on /dev/watchdog])]) ### Disable features ########################################################################### -AS_IF([test "x$enable_inetd" != "xno"], - enable_inetd="yes", [ - AC_DEFINE(INETD_DISABLED, 1, [Disable built-in inetd])]) +AS_IF([test "x$enable_inetd" != "xno"], [ + enable_inetd="yes" + AC_DEFINE(INETD_ENABLED, 1, [Enable built-in inetd])]) AS_IF([test "x$enable_quiet" != "xno"], [ AC_DEFINE(QUIET_MODE, 1, [Silent, after initial boot, no stopping/starting messages. Default: 1]) diff --git a/initctl.c b/initctl.c index 6e2ab2c7..89d00627 100644 --- a/initctl.c +++ b/initctl.c @@ -377,7 +377,7 @@ static int show_status(char *arg) continue; } -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd(svc)) { char *info; struct init_request rq = { @@ -401,7 +401,7 @@ static int show_status(char *arg) printf("%s %s\n", svc->cmd, info); } else -#endif /* !INETD_DISABLED */ +#endif /* INETD_ENABLED */ { int i; diff --git a/service.c b/service.c index e9b36c08..cd35e858 100644 --- a/service.c +++ b/service.c @@ -174,7 +174,7 @@ static int service_start(svc_t *svc) print_desc("", svc->desc); } -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd(svc)) { result = inetd_start(&svc->inetd); if (!silent) @@ -221,7 +221,7 @@ static int service_start(svc_t *svc) args[i] = NULL; /* Redirect inetd socket to stdin for connection */ -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd_conn(svc)) { dup2(svc->stdin_fd, STDIN_FILENO); close(svc->stdin_fd); @@ -287,7 +287,7 @@ static int service_start(svc_t *svc) else status = execv(svc->cmd, args); /* XXX: Maybe use execve() to be able to launch scripts? */ -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd_conn(svc)) { if (svc->inetd.type == SOCK_STREAM) { close(STDIN_FILENO); @@ -315,7 +315,7 @@ static int service_start(svc_t *svc) svc->pid = pid; -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd_conn(svc) && svc->inetd.type == SOCK_STREAM) close(svc->stdin_fd); #endif @@ -370,7 +370,7 @@ static int service_stop(svc_t *svc) if (!svc) return 1; -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd(svc)) { int do_print = runlevel != 1 && !silent && !svc_is_busy(svc); @@ -542,7 +542,7 @@ int service_register(int type, char *line, time_t mtime, char *username) { int i = 0; int id = 1; /* Default to ID:1 */ -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED int forking = 0; #endif int log = 0; @@ -581,7 +581,7 @@ int service_register(int type, char *line, time_t mtime, char *username) cond = &cmd[1]; else if (cmd[0] == ':') /* :ID */ id = atoi(&cmd[1]); -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED else if (!strncasecmp(cmd, "nowait", 6)) forking = 1; else if (!strncasecmp(cmd, "wait", 4)) @@ -612,7 +612,7 @@ int service_register(int type, char *line, time_t mtime, char *username) *proto++ = 0; } -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED /* Find plugin that provides a callback for this inetd service */ if (type == SVC_TYPE_INETD) { if (!strncasecmp(cmd, "internal", 8)) { @@ -651,7 +651,7 @@ recreate: return errno = ENOMEM; } } -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED else { if (svc_is_inetd(svc) && type != SVC_TYPE_INETD) { _d("Service was previously inetd, deregistering ..."); @@ -692,7 +692,7 @@ recreate: conf_parse_cond(svc, cond); -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd(svc)) { char *iface, *name = service; @@ -839,7 +839,7 @@ restart: break; case SVC_DONE_STATE: -#ifndef INETD_DISABLED +#ifdef INETD_ENABLED if (svc_is_inetd_conn(svc)) { if (svc_is_busy(svc->inetd.svc)) { svc_unblock(svc->inetd.svc);