From d5eb85ba1c0231a8a069215ae3c23d070072f53a Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Fri, 18 Nov 2022 00:04:00 +0100 Subject: [PATCH] Parse `--debug` parameter before forking To make sure the backend picks up the loglevel as well --- main.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 03f9682..1ff7919 100644 --- a/main.c +++ b/main.c @@ -1135,8 +1135,34 @@ static void term_in(int fd, short mask, void *data) { state.run_display = false; } -int main(int argc, char **argv) { +// Check for --debug 'early' we also apply the correct loglevel +// to the forked child, without having to first proces all of the +// configuration (including from file) before forking and (in the +// case of the shadow backend) dropping privileges +void log_init(int argc, char **argv) { + static struct option long_options[] = { + {"debug", no_argument, NULL, 'd'}, + {0, 0, 0, 0} + }; + int c; + optind = 1; + while (1) { + int opt_idx = 0; + c = getopt_long(argc, argv, "d", long_options, &opt_idx); + if (c == -1) { + break; + } + switch (c) { + case 'd': + swaylock_log_init(LOG_DEBUG); + return; + } + } swaylock_log_init(LOG_ERROR); +} + +int main(int argc, char **argv) { + log_init(argc, argv); initialize_pw_backend(argc, argv); srand(time(NULL));