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

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-07-02 12:38:35 +02:00
parent bd54cf6dee
commit e9d5512e1a
4 changed files with 22 additions and 52 deletions
+1 -2
View File
@@ -450,8 +450,7 @@ static int parse_conf(char *file)
strcat(line, " ");
}
if (!silent)
print(0, "Loading %sconfiguration", line);
print(0, "Loading %sconfiguration", line);
_d("Parsing %s", file);
while (!feof(fp)) {
+2 -2
View File
@@ -161,7 +161,7 @@ int run_interactive(char *cmd, char *fmt, ...)
return 1;
}
if (!silent && fmt) {
if (fmt) {
va_start(ap, fmt);
vsnprintf(line, sizeof(line), fmt, ap);
va_end(ap);
@@ -193,7 +193,7 @@ int run_interactive(char *cmd, char *fmt, ...)
}
}
if (!silent && fmt)
if (fmt)
print_result(status);
/* 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;
struct dirent *entry;
if (!silent)
print_desc("Loading plugins", NULL);
print_desc("Loading plugins", NULL);
dp = opendir(path);
if (!dp) {
@@ -336,9 +335,7 @@ static int load_plugins(char *path)
#else
static int load_plugins(char *UNUSED(path))
{
if (!silent)
print_desc("Initializing plugins", NULL);
print_desc("Initializing plugins", NULL);
return 0;
}
#endif /* ENABLE_STATIC */
@@ -350,10 +347,7 @@ int plugin_init(uev_ctx_t *ctx, char *path)
if (!load_plugins(path))
fail = init_plugins(ctx);
if (!silent)
print_result(fail);
return fail;
return print_result(fail);
}
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. */
if (!fexist(svc->cmd) && !svc->inetd.cmd) {
if (!silent) {
char msg[80];
snprintf(msg, sizeof(msg), "Service %s does not exist!", svc->cmd);
print_desc("", msg);
print_result(1);
}
print(1, "Service %s does not exist!", svc->cmd);
svc_missing(svc);
return 1;
}
@@ -166,20 +159,14 @@ static int service_start(svc_t *svc)
if (is_norespawn())
return 1;
if (!silent) {
if (svc_is_daemon(svc) || svc_is_inetd(svc))
print_desc("Starting ", svc->desc);
else
print_desc("", svc->desc);
}
if (svc_is_daemon(svc) || svc_is_inetd(svc))
print_desc("Starting ", svc->desc);
else
print_desc("", svc->desc);
#ifdef INETD_ENABLED
if (svc_is_inetd(svc)) {
result = inetd_start(&svc->inetd);
if (!silent)
print_result(result);
return result;
}
if (svc_is_inetd(svc))
return print_result(inetd_start(&svc->inetd));
#endif
/* Declare we're waiting for svc to create its pidfile */
@@ -316,7 +303,7 @@ static int service_start(svc_t *svc)
#ifdef INETD_ENABLED
if (svc_is_inetd_conn(svc) && svc->inetd.type == SOCK_STREAM)
close(svc->stdin_fd);
close(svc->stdin_fd);
#endif
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);
if (!silent)
print_result(result);
return 0;
return print_result(result);
}
/**
@@ -344,14 +328,14 @@ static void service_kill(svc_t *svc)
{
service_timeout_cancel(svc);
if (runlevel != 1 && !silent)
if (runlevel != 1)
print_desc("Killing ", svc->desc);
_d("Sending SIGKILL to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0));
kill(svc->pid, SIGKILL);
/* Let SIGKILLs stand out, show result as [WARN] */
if (runlevel != 1 && !silent)
if (runlevel != 1)
print(2, NULL);
}
@@ -371,7 +355,7 @@ static int service_stop(svc_t *svc)
#ifdef INETD_ENABLED
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)
print_desc("Stopping ", svc->desc);
@@ -392,13 +376,13 @@ static int service_stop(svc_t *svc)
if (SVC_TYPE_SERVICE != svc->type)
return 0;
if (runlevel != 1 && !silent)
if (runlevel != 1)
print_desc("Stopping ", svc->desc);
_d("Sending SIGTERM to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0));
res = kill(svc->pid, SIGTERM);
if (runlevel != 1 && !silent)
if (runlevel != 1)
print_result(res);
return res;
@@ -416,8 +400,6 @@ static int service_stop(svc_t *svc)
*/
static int service_restart(svc_t *svc)
{
int err;
/* Ignore if finit is SIGSTOP'ed */
if (is_norespawn())
return 1;
@@ -431,18 +413,13 @@ static int service_restart(svc_t *svc)
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 */
svc_starting(svc);
_d("Sending SIGHUP to PID %d", svc->pid);
err = kill(svc->pid, SIGHUP);
if (!silent)
print_result(err);
return err;
return print_result(kill(svc->pid, SIGHUP));
}
/**