]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children 8246/head
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 23:35:00 +0000 (00:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 23:35:00 +0000 (00:35 +0100)
In a number of occasions we use FORK_CLOSE_ALL_FDS when forking off a
child, since we don't want to pass fds to the processes spawned (either
because we later want to execve() some other process there, or because
our child might hang around for longer than expected, in which case it
shouldn't keep our fd pinned). This also closes any logging fds, and
thus means logging is turned off in the child. If we want to do proper
logging, explicitly reopen the logs hence in the child at the right
time.

This is particularly crucial in the umount/remount children we fork off
the shutdown binary, as otherwise the children can't log, which is
why #8155 is harder to debug than necessary: the log messages we
generate about failing mount() system calls aren't actually visible on
screen, as they done in the child processes where the log fds are
closed.

src/core/umount.c
src/coredump/coredumpctl.c
src/delta/delta.c
src/login/inhibit.c

index fa9c15ca36764721bd12bd90012c3099bc06d047..ff3e63710c5f6b8538490ef93fd161ce98677c9b 100644 (file)
@@ -390,7 +390,7 @@ static int remount_with_timeout(MountPoint *m, char *options, int *n_failed) {
          * fork a child process and set a timeout. If the timeout
          * lapses, the assumption is that that particular remount
          * failed. */
-        r = safe_fork("(sd-remount)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
+        r = safe_fork("(sd-remount)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_LOG|FORK_REOPEN_LOG, &pid);
         if (r < 0)
                 return r;
         if (r == 0) {
@@ -426,7 +426,7 @@ static int umount_with_timeout(MountPoint *m, bool *changed) {
          * fork a child process and set a timeout. If the timeout
          * lapses, the assumption is that that particular umount
          * failed. */
-        r = safe_fork("(sd-umount)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
+        r = safe_fork("(sd-umount)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_LOG|FORK_REOPEN_LOG, &pid);
         if (r < 0)
                 return r;
         if (r == 0) {
index 09178d5035e30366abca9a93e7d0f53fb2d4df88..6b697c37fc5008eff71df1a230bbdccaa5af1f1b 100644 (file)
@@ -932,6 +932,7 @@ static int run_gdb(sd_journal *j) {
                 goto finish;
         if (r == 0) {
                 execlp("gdb", "gdb", exe, path, NULL);
+                log_open();
                 log_error_errno(errno, "Failed to invoke gdb: %m");
                 _exit(EXIT_FAILURE);
         }
index 645b0b22780024a9a22e5a056c4f9f5bbb4216e1..4fe89ff9b0557022642311d31cb0b660ce13b2b6 100644 (file)
@@ -191,6 +191,7 @@ static int found_override(const char *top, const char *bottom) {
                 return r;
         if (r == 0) {
                 execlp("diff", "diff", "-us", "--", bottom, top, NULL);
+                log_open();
                 log_error_errno(errno, "Failed to execute diff: %m");
                 _exit(EXIT_FAILURE);
         }
index 22657f9eda010892f40e5f2115898d2629c04668..6b5d9c29b96d4f4847146eadec366a81800edbf4 100644 (file)
@@ -272,6 +272,7 @@ int main(int argc, char *argv[]) {
                 if (r == 0) {
                         /* Child */
                         execvp(argv[optind], argv + optind);
+                        log_open();
                         log_error_errno(errno, "Failed to execute %s: %m", argv[optind]);
                         _exit(EXIT_FAILURE);
                 }