]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredumpctl: fflush() stdout before invoking gdb
authorLennart Poettering <lennart@poettering.net>
Wed, 10 Mar 2021 20:54:59 +0000 (21:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 11 Mar 2021 07:55:20 +0000 (08:55 +0100)
Fixes: #18936
src/basic/process-util.c
src/basic/process-util.h
src/coredump/coredumpctl.c

index 4eb524d211279095f8eaefdf787e8647a27e7bd0..d3eb3ad18bade336795f54c0cb9f3164567d9cca 100644 (file)
@@ -1230,6 +1230,11 @@ int safe_fork_full(
 
         original_pid = getpid_cached();
 
+        if (flags & FORK_FLUSH_STDIO) {
+                fflush(stdout);
+                fflush(stderr); /* This one shouldn't be necessary, stderr should be unbuffered anyway, but let's better be safe than sorry */
+        }
+
         if (flags & (FORK_RESET_SIGNALS|FORK_DEATHSIG)) {
                 /* We temporarily block all signals, so that the new child has them blocked initially. This way, we can
                  * be sure that SIGTERMs are not lost we might send to the child. */
index bf709f6669a293c854a7f12586e283703e1cc8f0..ddce7bd2722b0b7155caa5f4e49295c5c8861788 100644 (file)
@@ -162,6 +162,7 @@ typedef enum ForkFlags {
         FORK_MOUNTNS_SLAVE      = 1 <<  9, /* Make child's mount namespace MS_SLAVE */
         FORK_RLIMIT_NOFILE_SAFE = 1 << 10, /* Set RLIMIT_NOFILE soft limit to 1K for select() compat */
         FORK_STDOUT_TO_STDERR   = 1 << 11, /* Make stdout a copy of stderr */
+        FORK_FLUSH_STDIO        = 1 << 12, /* fflush() stdout (and stderr) before forking */
 } ForkFlags;
 
 int safe_fork_full(const char *name, const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid);
index e1042d9bc4afa45f823c19bab25882fbb21fc0ec..0c4ef2e123486216213435956539b90482b4454c 100644 (file)
@@ -1116,7 +1116,7 @@ static int run_debug(int argc, char **argv, void *userdata) {
 
         fork_name = strjoina("(", debugger_call[0], ")");
 
-        r = safe_fork(fork_name, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
+        r = safe_fork(fork_name, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG|FORK_FLUSH_STDIO, &pid);
         if (r < 0)
                 goto finish;
         if (r == 0) {