From 2aab8734d457336651caad4e917f8600a8ec90c1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Apr 2025 08:28:33 +0530 Subject: [PATCH] reopen before forking so that if reopening fails we get a decent failure message --- kitty/launcher/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kitty/launcher/main.c b/kitty/launcher/main.c index f7d47704f..a8f0e608f 100644 --- a/kitty/launcher/main.c +++ b/kitty/launcher/main.c @@ -438,8 +438,6 @@ handle_option_value: exit(0); } if (opts.detach) { - if (fork() != 0) exit(0); - setsid(); #define reopen_or_fail(path, mode, which) { if (freopen(path, mode, which) == NULL) { int s = errno; fprintf(stderr, "Failed to redirect %s to %s with error: ", #which, path); errno = s; perror(NULL); exit(1); } } if (!(opts.session && ((opts.session[0] == '-' && opts.session[1] == 0) || strcmp(opts.session, "/dev/stdin") == 0)) ) reopen_or_fail("/dev/null", "rb", stdin); @@ -447,6 +445,8 @@ handle_option_value: reopen_or_fail(opts.detached_log, "ab", stdout); reopen_or_fail(opts.detached_log, "ab", stderr); #undef reopen_or_fail + if (fork() != 0) exit(0); + setsid(); } unsetenv("KITTY_SI_DATA"); if (opts.single_instance) {