Show log output even in verbose mode

Compiling with -DDEBUG isn't required to show output of commands,
verbose mode is sufficient.
This commit is contained in:
Johannes Bauer 2018-01-16 19:40:13 +01:00
parent bc291dcbd8
commit 1c61480b71
5 changed files with 7 additions and 11 deletions

9
exec.c
View File

@ -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);

2
exec.h
View File

@ -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

2
log.c
View File

@ -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;
}

1
log.h
View File

@ -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, ...);

4
luks.c
View File

@ -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);
}