chiark / gitweb /
tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 23:35:00 +0000 (00:35 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:02 +0000 (07:59 +0200)
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/login/inhibit.c

index 7e6812c2da1ddc6b3de079e61467ff10e23c7094..1ef98daa22a5b2f5e77cdb3b303ed70bf6f5e447 100644 (file)
@@ -276,6 +276,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);
                 }