From 1c61480b71924326b3ff399e8fad7177dc95859c Mon Sep 17 00:00:00 2001 From: Johannes Bauer Date: Tue, 16 Jan 2018 19:40:13 +0100 Subject: [PATCH] Show log output even in verbose mode Compiling with -DDEBUG isn't required to show output of commands, verbose mode is sufficient. --- exec.c | 9 ++------- exec.h | 2 +- log.c | 2 +- log.h | 1 + luks.c | 4 ++-- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/exec.c b/exec.c index 5e2815c..01d44cf 100644 --- a/exec.c +++ b/exec.c @@ -78,7 +78,7 @@ static char **argv_dup(const char **argv) { return result; } -struct runresult_t exec_command(const char **argv) { +struct runresult_t exec_command(const char **argv, bool show_output) { struct runresult_t runresult; char **argvcopy = argv_dup(argv); @@ -93,12 +93,7 @@ struct runresult_t exec_command(const char **argv) { } if (pid == 0) { /* Child */ -#ifdef DEBUG - const bool silent = true; -#else - const bool silent = false; -#endif - if (silent) { + if (!show_output) { /* Shut up the child if user did not request debug output */ close(1); close(2); diff --git a/exec.h b/exec.h index 27952b4..96cc988 100644 --- a/exec.h +++ b/exec.h @@ -33,7 +33,7 @@ struct runresult_t { /*************** AUTO GENERATED SECTION FOLLOWS ***************/ void argv_dump(const char **argv); -struct runresult_t exec_command(const char **argv); +struct runresult_t exec_command(const char **argv, bool show_output); /*************** AUTO GENERATED SECTION ENDS ***************/ #endif diff --git a/log.c b/log.c index 4d2ce4b..1ce4984 100644 --- a/log.c +++ b/log.c @@ -51,7 +51,7 @@ static void log_suffix(void) { fprintf(stderr, "\n"); } -static bool should_log(enum loglvl_t level) { +bool should_log(enum loglvl_t level) { return level <= current_loglvl; } diff --git a/log.h b/log.h index f5febba..bf5c57e 100644 --- a/log.h +++ b/log.h @@ -34,6 +34,7 @@ enum loglvl_t { /*************** AUTO GENERATED SECTION FOLLOWS ***************/ void log_setlvl(enum loglvl_t level); +bool should_log(enum loglvl_t level); void log_msg(enum loglvl_t level, const char *msg, ...); void log_libc(enum loglvl_t level, const char *msg, ...); void log_openssl(enum loglvl_t level, const char *msg, ...); diff --git a/luks.c b/luks.c index a1dc82d..0bb82ae 100644 --- a/luks.c +++ b/luks.c @@ -42,7 +42,7 @@ bool is_luks_device_opened(const char *mapping_name) { mapping_name, NULL, }; - struct runresult_t runresult = exec_command(command); + struct runresult_t runresult = exec_command(command, should_log(LLVL_DEBUG)); return runresult.success && (runresult.returncode == 0); } @@ -62,7 +62,7 @@ bool open_luks_device(const uint8_t *encrypted_device_uuid, const char *mapping_ NULL, }; - struct runresult_t runresult = exec_command(command); + struct runresult_t runresult = exec_command(command, should_log(LLVL_DEBUG)); return runresult.success && (runresult.returncode == 0); }