Refactor, simplify ... print() APIs already check if silent

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-07-02 12:38:35 +02:00
1 parent bd54cf6dee
commit e9d5512e1a
4 files changed
+22 -52

No files matched your search

+1 -2
View File
@@ -450,8 +450,7 @@ static int parse_conf(char *file)
strcat(line, " "); strcat(line, " ");
} }
if (!silent) print(0, "Loading %sconfiguration", line);
print(0, "Loading %sconfiguration", line);
_d("Parsing %s", file); _d("Parsing %s", file);
while (!feof(fp)) { while (!feof(fp)) {
+2 -2
View File
@@ -161,7 +161,7 @@ int run_interactive(char *cmd, char *fmt, ...)
return 1; return 1;
} }
if (!silent && fmt) { if (fmt) {
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(line, sizeof(line), fmt, ap); vsnprintf(line, sizeof(line), fmt, ap);
va_end(ap); va_end(ap);
@@ -193,7 +193,7 @@ int run_interactive(char *cmd, char *fmt, ...)
} }
} }
if (!silent && fmt) if (fmt)
print_result(status); print_result(status);
/* Dump any results of cmd on stderr after we've printed [ OK ] or [FAIL] */ /* Dump any results of cmd on stderr after we've printed [ OK ] or [FAIL] */
+3 -9
View File
@@ -311,8 +311,7 @@ static int load_plugins(char *path)
DIR *dp; DIR *dp;
struct dirent *entry; struct dirent *entry;
if (!silent) print_desc("Loading plugins", NULL);
print_desc("Loading plugins", NULL);
dp = opendir(path); dp = opendir(path);
if (!dp) { if (!dp) {
@@ -336,9 +335,7 @@ static int load_plugins(char *path)
#else #else
static int load_plugins(char *UNUSED(path)) static int load_plugins(char *UNUSED(path))
{ {
if (!silent) print_desc("Initializing plugins", NULL);
print_desc("Initializing plugins", NULL);
return 0; return 0;
} }
#endif /* ENABLE_STATIC */ #endif /* ENABLE_STATIC */
@@ -350,10 +347,7 @@ int plugin_init(uev_ctx_t *ctx, char *path)
if (!load_plugins(path)) if (!load_plugins(path))
fail = init_plugins(ctx); fail = init_plugins(ctx);
if (!silent) return print_result(fail);
print_result(fail);
return fail;
} }
void plugin_exit(void) void plugin_exit(void)
+16 -39
View File
@@ -150,14 +150,7 @@ static int service_start(svc_t *svc)
/* Don't try and start service if it doesn't exist. */ /* Don't try and start service if it doesn't exist. */
if (!fexist(svc->cmd) && !svc->inetd.cmd) { if (!fexist(svc->cmd) && !svc->inetd.cmd) {
if (!silent) { print(1, "Service %s does not exist!", svc->cmd);
char msg[80];
snprintf(msg, sizeof(msg), "Service %s does not exist!", svc->cmd);
print_desc("", msg);
print_result(1);
}
svc_missing(svc); svc_missing(svc);
return 1; return 1;
} }
@@ -166,20 +159,14 @@ static int service_start(svc_t *svc)
if (is_norespawn()) if (is_norespawn())
return 1; return 1;
if (!silent) { if (svc_is_daemon(svc) || svc_is_inetd(svc))
if (svc_is_daemon(svc) || svc_is_inetd(svc)) print_desc("Starting ", svc->desc);
print_desc("Starting ", svc->desc); else
else print_desc("", svc->desc);
print_desc("", svc->desc);
}
#ifdef INETD_ENABLED #ifdef INETD_ENABLED
if (svc_is_inetd(svc)) { if (svc_is_inetd(svc))
result = inetd_start(&svc->inetd); return print_result(inetd_start(&svc->inetd));
if (!silent)
print_result(result);
return result;
}
#endif #endif
/* Declare we're waiting for svc to create its pidfile */ /* Declare we're waiting for svc to create its pidfile */
@@ -316,7 +303,7 @@ static int service_start(svc_t *svc)
#ifdef INETD_ENABLED #ifdef INETD_ENABLED
if (svc_is_inetd_conn(svc) && svc->inetd.type == SOCK_STREAM) if (svc_is_inetd_conn(svc) && svc->inetd.type == SOCK_STREAM)
close(svc->stdin_fd); close(svc->stdin_fd);
#endif #endif
plugin_run_hook(HOOK_SVC_START, (void *)(uintptr_t)pid); plugin_run_hook(HOOK_SVC_START, (void *)(uintptr_t)pid);
@@ -328,10 +315,7 @@ static int service_start(svc_t *svc)
sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL);
if (!silent) return print_result(result);
print_result(result);
return 0;
} }
/** /**
@@ -344,14 +328,14 @@ static void service_kill(svc_t *svc)
{ {
service_timeout_cancel(svc); service_timeout_cancel(svc);
if (runlevel != 1 && !silent) if (runlevel != 1)
print_desc("Killing ", svc->desc); print_desc("Killing ", svc->desc);
_d("Sending SIGKILL to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0)); _d("Sending SIGKILL to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0));
kill(svc->pid, SIGKILL); kill(svc->pid, SIGKILL);
/* Let SIGKILLs stand out, show result as [WARN] */ /* Let SIGKILLs stand out, show result as [WARN] */
if (runlevel != 1 && !silent) if (runlevel != 1)
print(2, NULL); print(2, NULL);
} }
@@ -371,7 +355,7 @@ static int service_stop(svc_t *svc)
#ifdef INETD_ENABLED #ifdef INETD_ENABLED
if (svc_is_inetd(svc)) { if (svc_is_inetd(svc)) {
int do_print = runlevel != 1 && !silent && !svc_is_busy(svc); int do_print = runlevel != 1 && !svc_is_busy(svc);
if (do_print) if (do_print)
print_desc("Stopping ", svc->desc); print_desc("Stopping ", svc->desc);
@@ -392,13 +376,13 @@ static int service_stop(svc_t *svc)
if (SVC_TYPE_SERVICE != svc->type) if (SVC_TYPE_SERVICE != svc->type)
return 0; return 0;
if (runlevel != 1 && !silent) if (runlevel != 1)
print_desc("Stopping ", svc->desc); print_desc("Stopping ", svc->desc);
_d("Sending SIGTERM to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0)); _d("Sending SIGTERM to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0));
res = kill(svc->pid, SIGTERM); res = kill(svc->pid, SIGTERM);
if (runlevel != 1 && !silent) if (runlevel != 1)
print_result(res); print_result(res);
return res; return res;
@@ -416,8 +400,6 @@ static int service_stop(svc_t *svc)
*/ */
static int service_restart(svc_t *svc) static int service_restart(svc_t *svc)
{ {
int err;
/* Ignore if finit is SIGSTOP'ed */ /* Ignore if finit is SIGSTOP'ed */
if (is_norespawn()) if (is_norespawn())
return 1; return 1;
@@ -431,18 +413,13 @@ static int service_restart(svc_t *svc)
return 1; return 1;
} }
if (!silent) print_desc("Restarting ", svc->desc);
print_desc("Restarting ", svc->desc);
/* Declare we're waiting for svc to re-assert/touch its pidfile */ /* Declare we're waiting for svc to re-assert/touch its pidfile */
svc_starting(svc); svc_starting(svc);
_d("Sending SIGHUP to PID %d", svc->pid); _d("Sending SIGHUP to PID %d", svc->pid);
err = kill(svc->pid, SIGHUP); return print_result(kill(svc->pid, SIGHUP));
if (!silent)
print_result(err);
return err;
} }
/** /**