From 0dd97de046be3b6e621034a9c5ee1e051106fed3 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 7 Jun 2015 15:57:11 +0200 Subject: [PATCH] Add --enable-quiet to configure, makes Finit real quiet. Signed-off-by: Joachim Nilsson --- conf.c | 3 ++- configure | 24 ++++++++++++++++++------ finit.c | 4 ++-- finit.h | 2 ++ helpers.c | 7 +++++-- helpers.h | 3 --- plugin.c | 9 +++++++-- service.c | 33 +++++++++++++++++++-------------- svc.c | 1 + 9 files changed, 56 insertions(+), 30 deletions(-) diff --git a/conf.c b/conf.c index dc799a64..8e98084b 100644 --- a/conf.c +++ b/conf.c @@ -319,7 +319,8 @@ static int parse_conf(char *file) strcat(line, " "); } - print(0, "Loading %sconfiguration", line); + if (verbose) + print(0, "Loading %sconfiguration", line); while (!feof(fp)) { if (!fgets(line, sizeof(line), fp)) continue; diff --git a/configure b/configure index 40625008..b675ebc8 100755 --- a/configure +++ b/configure @@ -28,6 +28,7 @@ defaults() debug=${debug:=0} embedded=${embedded:=0} inetd=${inetd:=1} + verbose=${verbose:=1} static=${static:=0} disable_plugins=${disable_plugins:=0} } @@ -59,8 +60,13 @@ fi else echo "Inetd : DISABLED" fi + if [ $verbose -ne 1 ]; then + echo "Quiet Finit : YES" + else + echo "Quiet Finit : NO, verbose output (default)" + fi if [ $static -ne 0 ]; then - echo "Static finit : YES" + echo "Static Finit : YES" fi if [ $disable_plugins -eq 1 ]; then echo "Plugins : DISABLED" @@ -98,7 +104,8 @@ usage() echo echo " --enable-embedded Enable embedded defaults, BusBox getty, mdev etc." echo " --enable-debug Enable debug flags, '-O0, -g'" - echo " --enable-static Link finit statically. This disables a few features." + echo " --enable-quiet Quiet mode, reduce screen output to absolute minimum." + echo " --enable-static Link statically. This disables a few features." echo " --disable-inetd Disable inetd support if not needed." echo " --disable-plugins Disable plugins" echo @@ -171,6 +178,14 @@ while [ "$*" != "" ]; do embedded=1 ;; + enable-quiet) + verbose=0 + ;; + + enable-static) + static=1 + ;; + disable-inetd) inetd=0 ;; @@ -179,10 +194,6 @@ while [ "$*" != "" ]; do disable_plugins=1 ;; - enable-static) - static=1 - ;; - help) usage ;; @@ -263,6 +274,7 @@ if [ x"$heading" != x"" ]; then echo "#define INIT_HEADING \"$heading\"" >> config.h fi +echo "#define VERBOSE_MODE $verbose" >> config.h echo "#define FINIT_FIFO \"$fifo\"" >> config.h echo "#define FINIT_CONF \"$config\"" >> config.h echo "#define FINIT_RCSD \"$rcsd\"" >> config.h diff --git a/finit.c b/finit.c index 37f5745d..dfb6f045 100644 --- a/finit.c +++ b/finit.c @@ -38,7 +38,7 @@ #include "inetd.h" int debug = 0; -int verbose = 1; +int verbose = VERBOSE_MODE; int runlevel = 0; /* Bootstrap */ int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */ int prevlevel = 0; /* HALT */ @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) * Load plugins first, finit.conf may contain references to * features implemented by plugins. */ - print_result(plugin_load_all(&loop, PLUGIN_PATH)); + plugin_load_all(&loop, PLUGIN_PATH); /* * Parse configuration file diff --git a/finit.h b/finit.h index 073340ad..faf3adba 100644 --- a/finit.h +++ b/finit.h @@ -87,6 +87,8 @@ struct init_request { char data[368]; }; +extern int debug; +extern int verbose; extern int runlevel; extern int cfglevel; extern int prevlevel; diff --git a/helpers.c b/helpers.c index 00190ddb..9507244a 100644 --- a/helpers.c +++ b/helpers.c @@ -172,6 +172,9 @@ char *runlevel_string(int levels) */ int banner(void) { + if (getpid() == 1 && !verbose) + return 0; + delline(); #ifdef INIT_HEADING echo("%s", INIT_HEADING); @@ -515,7 +518,7 @@ int run_interactive(char *cmd, char *fmt, ...) return 1; } - if (fmt) { + if (verbose && fmt) { va_start(ap, fmt); vsnprintf(line, sizeof(line), fmt, ap); va_end(ap); @@ -547,7 +550,7 @@ int run_interactive(char *cmd, char *fmt, ...) } } - if (fmt) + if (verbose && fmt) print_result(status); /* Dump any results of cmd on stderr after we've printed [ OK ] or [FAIL] */ diff --git a/helpers.h b/helpers.h index aabc389d..dacbc429 100644 --- a/helpers.h +++ b/helpers.h @@ -88,9 +88,6 @@ do { \ #define SETBIT(a,i) (a |= (1 << (i))) #define CLRBIT(a,i) (a &= ~(1 << (i))) -extern int debug; -extern int verbose; - int makepath (char *path); void ifconfig (char *ifname, char *addr, char *mask, int up); diff --git a/plugin.c b/plugin.c index 8973da24..1de421b8 100644 --- a/plugin.c +++ b/plugin.c @@ -295,10 +295,12 @@ int plugin_load_all(uev_ctx_t *ctx, char *path) DIR *dp = opendir(path); struct dirent *entry; - print_desc("Loading plugins", NULL); + if (verbose) + print_desc("Loading plugins", NULL); if (!dp) { _e("Failed, cannot open plugin directory %s: %s", path, strerror(errno)); - return 1; + fail = 1; + goto exit; } plugpath = path; @@ -319,6 +321,9 @@ int plugin_load_all(uev_ctx_t *ctx, char *path) /* Always initialize plugins */ init_plugins(ctx); +exit: + if (verbose) + print_result(fail); return fail; } diff --git a/service.c b/service.c index 51f83db4..93045e6e 100644 --- a/service.c +++ b/service.c @@ -145,11 +145,13 @@ int service_start(svc_t *svc) /* Don't try and start service if it doesn't exist. */ if (!fexist(svc->cmd) && !svc->inetd.cmd) { - char msg[80]; + if (verbose) { + char msg[80]; - snprintf(msg, sizeof(msg), "Service %s does not exist!", svc->cmd); - print_desc("", msg); - print_result(1); + snprintf(msg, sizeof(msg), "Service %s does not exist!", svc->cmd); + print_desc("", msg); + print_result(1); + } return 0; } @@ -193,10 +195,12 @@ int service_start(svc_t *svc) FLOG_INFO("Starting inetd service %s for requst from iface %s ...", svc->inetd.name, ifname); } else #endif - if (svc_is_daemon(svc)) - print_desc("", svc->desc); - else if (!respawn) - print_desc("Starting ", svc->desc); + if (verbose) { + if (svc_is_daemon(svc)) + print_desc("", svc->desc); + else if (!respawn) + print_desc("Starting ", svc->desc); + } /* Block sigchild while forking. */ sigemptyset(&nmask); @@ -281,11 +285,12 @@ int service_start(svc_t *svc) if (svc_is_inetd(svc)) { if (svc->inetd.type == SOCK_STREAM) close(sd); + } else if (verbose) { + if (SVC_TYPE_RUN == svc->type) + print_result(WEXITSTATUS(complete(svc->cmd, pid))); + else if (!respawn) + print_result(svc->pid > 1 ? 0 : 1); } - else if (SVC_TYPE_RUN == svc->type) - print_result(WEXITSTATUS(complete(svc->cmd, pid))); - else if (!respawn) - print_result(svc->pid > 1 ? 0 : 1); return 0; } @@ -308,13 +313,13 @@ int service_stop(svc_t *svc) if (SVC_TYPE_SERVICE != svc->type) return 0; - if (runlevel != 1) + if (runlevel != 1 && verbose) 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) + if (runlevel != 1 && verbose) print_result(res); exit: svc->pid = 0; diff --git a/svc.c b/svc.c index 2cc1ab36..229a1257 100644 --- a/svc.c +++ b/svc.c @@ -24,6 +24,7 @@ #include +#include "finit.h" #include "svc.h" #include "helpers.h"