mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-04 17:47:03 +03:00
tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children
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.
This commit is contained in:
parent
e18805fbd0
commit
0b1f3c768c
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user