log.c: New log_is_debug() function, hide access to debug variable

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-07-02 12:40:50 +02:00
1 parent e9d5512e1a
commit 51e1a907e6
6 files changed
+18 -11

No files matched your search

+3 -3
View File
@@ -171,7 +171,7 @@ int run_interactive(char *cmd, char *fmt, ...)
/* Redirect output from cmd to a tempfile */ /* Redirect output from cmd to a tempfile */
fp = tempfile(); fp = tempfile();
if (fp && !debug) { if (fp && !log_is_debug()) {
oldout = dup(STDOUT_FILENO); oldout = dup(STDOUT_FILENO);
olderr = dup(STDERR_FILENO); olderr = dup(STDERR_FILENO);
dup2(fileno(fp), STDOUT_FILENO); dup2(fileno(fp), STDOUT_FILENO);
@@ -182,7 +182,7 @@ int run_interactive(char *cmd, char *fmt, ...)
status = run(cmd); status = run(cmd);
/* Restore stderr/stdout */ /* Restore stderr/stdout */
if (fp && !debug) { if (fp && !log_is_debug()) {
if (oldout >= 0) { if (oldout >= 0) {
dup2(oldout, STDOUT_FILENO); dup2(oldout, STDOUT_FILENO);
close(oldout); close(oldout);
@@ -197,7 +197,7 @@ int run_interactive(char *cmd, char *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] */
if (fp && !debug) { if (fp && !log_is_debug()) {
size_t len, written; size_t len, written;
rewind(fp); rewind(fp);
+5 -5
View File
@@ -47,7 +47,6 @@
#include "utmp-api.h" #include "utmp-api.h"
#include "watchdog.h" #include "watchdog.h"
int debug = 0;
int quiet = QUIET_MODE; /* Delayed disable of silent mode. */ int quiet = QUIET_MODE; /* Delayed disable of silent mode. */
int silent = SILENT_MODE; /* Completely silent, including boot */ int silent = SILENT_MODE; /* Completely silent, including boot */
int wdogpid = 0; /* No watchdog by default */ int wdogpid = 0; /* No watchdog by default */
@@ -112,8 +111,8 @@ static int fsck(int pass)
return 1; return 1;
} }
save = debug; if ((save = log_is_debug()))
debug = 0; log_debug();
while ((fs = getfsent())) { while ((fs = getfsent())) {
char cmd[80]; char cmd[80];
@@ -139,7 +138,8 @@ static int fsck(int pass)
run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec); run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
} }
debug = save; if (save)
log_debug();
endfsent(); endfsent();
return 0; return 0;
@@ -311,7 +311,7 @@ int main(int argc, char* argv[])
*/ */
if (fexist("/sbin/mdev")) { if (fexist("/sbin/mdev")) {
/* Embedded Linux systems usually have BusyBox mdev */ /* Embedded Linux systems usually have BusyBox mdev */
if (debug) if (log_is_debug())
touch("/dev/mdev.log"); touch("/dev/mdev.log");
devfsd = "/sbin/mdev -s"; devfsd = "/sbin/mdev -s";
} else { } else {
-1
View File
@@ -89,7 +89,6 @@ struct init_request {
char data[368]; char data[368];
}; };
extern int debug;
extern int quiet; extern int quiet;
extern int silent; extern int silent;
extern int wdogpid; extern int wdogpid;
+6
View File
@@ -30,6 +30,7 @@
#include "finit.h" #include "finit.h"
#include "log.h" #include "log.h"
static int debug = 0;
static int loglevel = LOG_NOTICE; static int loglevel = LOG_NOTICE;
void log_init(int qit, int dbg) void log_init(int qit, int dbg)
@@ -63,6 +64,11 @@ void log_debug(void)
logit(LOG_NOTICE, "Debug mode %s", debug ? "enabled" : "disabled"); 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) static void early_logit(int prio, const char *fmt, va_list ap)
{ {
FILE *fp; FILE *fp;
+2
View File
@@ -44,6 +44,8 @@ void log_init (int qit, int dbg);
void log_exit (void); void log_exit (void);
void log_debug (void); void log_debug (void);
int log_is_debug (void);
void logit (int prio, const char *fmt, ...); void logit (int prio, const char *fmt, ...);
#endif /* FINIT_LOG_H_ */ #endif /* FINIT_LOG_H_ */
+2 -2
View File
@@ -255,7 +255,7 @@ static int service_start(svc_t *svc)
dup2(fd, STDOUT_FILENO); dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO); dup2(fd, STDERR_FILENO);
close(fd); close(fd);
} else if (debug) { } else if (log_is_debug()) {
int fd; int fd;
fd = open(CONSOLE, O_WRONLY | O_APPEND); fd = open(CONSOLE, O_WRONLY | O_APPEND);
@@ -286,7 +286,7 @@ static int service_start(svc_t *svc)
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
exit(status); exit(status);
} else if (debug) { } else if (log_is_debug()) {
char buf[CMD_SIZE] = ""; char buf[CMD_SIZE] = "";
for (i = 0; i < (MAX_NUM_SVC_ARGS - 1) && svc->args[i][0] != 0; i++) { for (i = 0; i < (MAX_NUM_SVC_ARGS - 1) && svc->args[i][0] != 0; i++) {