From 87e4e10f15b28097d970ac22e99cc60d81370aff Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 10 Nov 2019 19:10:32 +0000 Subject: [PATCH] core: reinitialize logging after resets deinit then init the logging system after resets, because otherwise duplicated log handlers will be added by session_init, and we will see duplicated logs. Doing this also enables us to add log handlers for early logging. Signed-off-by: Yuxuan Shui --- src/picom.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/picom.c b/src/picom.c index 2fc1939..51031c4 100644 --- a/src/picom.c +++ b/src/picom.c @@ -2335,25 +2335,35 @@ int main(int argc, char **argv) { // Main loop bool quit = false; + int ret_code = 0; do { Display *dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Can't open display."); - return 1; + ret_code = 1; + break; } XSetEventQueueOwner(dpy, XCBOwnsEventQueue); + + // Reinit logging system so we don't get leftovers from previous sessions + // or early logging. + log_deinit_tls(); + log_init_tls(); + ps_g = session_init(argc, argv, dpy, config_file, all_xerrors, need_fork); if (!ps_g) { log_fatal("Failed to create new session."); - return 1; + ret_code = 1; + break; } if (need_fork) { // Finishing up daemonization // Close files if (fclose(stdout) || fclose(stderr) || fclose(stdin)) { log_fatal("Failed to close standard input/output"); - return 1; + ret_code = 1; + break; } // Make us the session and process group leader so we don't get // killed when our parent die. @@ -2380,5 +2390,5 @@ int main(int argc, char **argv) { log_deinit_tls(); - return 0; + return ret_code; }