summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-10 21:54:59 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-12 17:35:57 +0100
commit6c9b5a50c97285b1a345481de98d6932ae503e9e (patch)
tree72a0a8cdadde63d0550c869acae18860b30f3a63
parent4c9396d4d21c1b756badc4b2dc946fc0dd62690c (diff)
downloadsystemd-6c9b5a50c97285b1a345481de98d6932ae503e9e.tar.gz
coredumpctl: fflush() stdout before invoking gdb
Fixes: #18936 (cherry picked from commit 48f813c4aab307695b853cbd3ea3c85f22486898)
-rw-r--r--src/basic/process-util.c5
-rw-r--r--src/basic/process-util.h1
-rw-r--r--src/coredump/coredumpctl.c2
3 files changed, 7 insertions, 1 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 0851613fc9..adfebd68b6 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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. */
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index 6144f142c4..18ac961f7b 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -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);
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index b4e64c60ce..c4c02cffdc 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -988,7 +988,7 @@ static int run_debug(int argc, char **argv, void *userdata) {
fork_name = strjoina("(", debugger, ")");
- 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) {