From 51e1a907e6ccfb1477efdea9530c988fdeafadde Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 2 Jul 2017 12:40:50 +0200 Subject: [PATCH] log.c: New log_is_debug() function, hide access to debug variable Signed-off-by: Joachim Nilsson --- src/exec.c | 6 +++--- src/finit.c | 10 +++++----- src/finit.h | 1 - src/log.c | 6 ++++++ src/log.h | 2 ++ src/service.c | 4 ++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/exec.c b/src/exec.c index 2954da41..97913965 100644 --- a/src/exec.c +++ b/src/exec.c @@ -171,7 +171,7 @@ int run_interactive(char *cmd, char *fmt, ...) /* Redirect output from cmd to a tempfile */ fp = tempfile(); - if (fp && !debug) { + if (fp && !log_is_debug()) { oldout = dup(STDOUT_FILENO); olderr = dup(STDERR_FILENO); dup2(fileno(fp), STDOUT_FILENO); @@ -182,7 +182,7 @@ int run_interactive(char *cmd, char *fmt, ...) status = run(cmd); /* Restore stderr/stdout */ - if (fp && !debug) { + if (fp && !log_is_debug()) { if (oldout >= 0) { dup2(oldout, STDOUT_FILENO); close(oldout); @@ -197,7 +197,7 @@ int run_interactive(char *cmd, char *fmt, ...) print_result(status); /* Dump any results of cmd on stderr after we've printed [ OK ] or [FAIL] */ - if (fp && !debug) { + if (fp && !log_is_debug()) { size_t len, written; rewind(fp); diff --git a/src/finit.c b/src/finit.c index 6861d862..3879ad59 100644 --- a/src/finit.c +++ b/src/finit.c @@ -47,7 +47,6 @@ #include "utmp-api.h" #include "watchdog.h" -int debug = 0; int quiet = QUIET_MODE; /* Delayed disable of silent mode. */ int silent = SILENT_MODE; /* Completely silent, including boot */ int wdogpid = 0; /* No watchdog by default */ @@ -112,8 +111,8 @@ static int fsck(int pass) return 1; } - save = debug; - debug = 0; + if ((save = log_is_debug())) + log_debug(); while ((fs = getfsent())) { char cmd[80]; @@ -139,7 +138,8 @@ static int fsck(int pass) run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec); } - debug = save; + if (save) + log_debug(); endfsent(); return 0; @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) */ if (fexist("/sbin/mdev")) { /* Embedded Linux systems usually have BusyBox mdev */ - if (debug) + if (log_is_debug()) touch("/dev/mdev.log"); devfsd = "/sbin/mdev -s"; } else { diff --git a/src/finit.h b/src/finit.h index 56dc4507..424781db 100644 --- a/src/finit.h +++ b/src/finit.h @@ -89,7 +89,6 @@ struct init_request { char data[368]; }; -extern int debug; extern int quiet; extern int silent; extern int wdogpid; diff --git a/src/log.c b/src/log.c index 900d9be2..d6061f9a 100644 --- a/src/log.c +++ b/src/log.c @@ -30,6 +30,7 @@ #include "finit.h" #include "log.h" +static int debug = 0; static int loglevel = LOG_NOTICE; void log_init(int qit, int dbg) @@ -63,6 +64,11 @@ void log_debug(void) logit(LOG_NOTICE, "Debug mode %s", debug ? "enabled" : "disabled"); } +int log_is_debug(void) +{ + return debug; +} + static void early_logit(int prio, const char *fmt, va_list ap) { FILE *fp; diff --git a/src/log.h b/src/log.h index 860cdb2e..4c7a621d 100644 --- a/src/log.h +++ b/src/log.h @@ -44,6 +44,8 @@ void log_init (int qit, int dbg); void log_exit (void); void log_debug (void); +int log_is_debug (void); + void logit (int prio, const char *fmt, ...); #endif /* FINIT_LOG_H_ */ diff --git a/src/service.c b/src/service.c index 3998025c..333af972 100644 --- a/src/service.c +++ b/src/service.c @@ -255,7 +255,7 @@ static int service_start(svc_t *svc) dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); close(fd); - } else if (debug) { + } else if (log_is_debug()) { int fd; fd = open(CONSOLE, O_WRONLY | O_APPEND); @@ -286,7 +286,7 @@ static int service_start(svc_t *svc) waitpid(pid, NULL, 0); exit(status); - } else if (debug) { + } else if (log_is_debug()) { char buf[CMD_SIZE] = ""; for (i = 0; i < (MAX_NUM_SVC_ARGS - 1) && svc->args[i][0] != 0; i++) {