1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 07:51:21 +03:00

Merge pull request #8246 from poettering/wait-for-terminate-eproto

some shutdown logging fixes
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-02-22 08:27:44 +01:00 committed by GitHub
commit a4896a1f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 39 deletions

View File

@ -613,22 +613,16 @@ int log_dispatch_internal(
LOG_TARGET_JOURNAL)) {
k = write_to_journal(level, error, file, line, func, object_field, object, extra_field, extra, buffer);
if (k < 0) {
if (k != -EAGAIN)
log_close_journal();
log_open_kmsg();
}
if (k < 0 && k != -EAGAIN)
log_close_journal();
}
if (IN_SET(log_target, LOG_TARGET_SYSLOG_OR_KMSG,
LOG_TARGET_SYSLOG)) {
k = write_to_syslog(level, error, file, line, func, buffer);
if (k < 0) {
if (k != -EAGAIN)
log_close_syslog();
log_open_kmsg();
}
if (k < 0 && k != -EAGAIN)
log_close_syslog();
}
if (k <= 0 &&
@ -637,6 +631,9 @@ int log_dispatch_internal(
LOG_TARGET_JOURNAL_OR_KMSG,
LOG_TARGET_KMSG)) {
if (k < 0)
log_open_kmsg();
k = write_to_kmsg(level, error, file, line, func, buffer);
if (k < 0) {
log_close_kmsg();

View File

@ -93,14 +93,14 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_LOG_LEVEL:
r = log_set_max_level_from_string(optarg);
if (r < 0)
log_error("Failed to parse log level %s, ignoring.", optarg);
log_error_errno(r, "Failed to parse log level %s, ignoring.", optarg);
break;
case ARG_LOG_TARGET:
r = log_set_target_from_string(optarg);
if (r < 0)
log_error("Failed to parse log target %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log target %s, ignoring", optarg);
break;
@ -109,7 +109,7 @@ static int parse_argv(int argc, char *argv[]) {
if (optarg) {
r = log_show_color_from_string(optarg);
if (r < 0)
log_error("Failed to parse log color setting %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log color setting %s, ignoring", optarg);
} else
log_show_color(true);
@ -119,7 +119,7 @@ static int parse_argv(int argc, char *argv[]) {
if (optarg) {
r = log_show_location_from_string(optarg);
if (r < 0)
log_error("Failed to parse log location setting %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log location setting %s, ignoring", optarg);
} else
log_show_location(true);
@ -128,14 +128,14 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_EXIT_CODE:
r = safe_atou8(optarg, &arg_exit_code);
if (r < 0)
log_error("Failed to parse exit code %s, ignoring", optarg);
log_error_errno(r, "Failed to parse exit code %s, ignoring", optarg);
break;
case ARG_TIMEOUT:
r = parse_sec(optarg, &arg_timeout);
if (r < 0)
log_error("Failed to parse shutdown timeout %s, ignoring", optarg);
log_error_errno(r, "Failed to parse shutdown timeout %s, ignoring", optarg);
break;
@ -276,15 +276,18 @@ int main(int argc, char *argv[]) {
static const char* const dirs[] = {SYSTEM_SHUTDOWN_PATH, NULL};
char *watchdog_device;
/* The log target defaults to console, but the original systemd process will pass its log target in through a
* command line argument, which will override this default. Also, ensure we'll never log to the journal or
* syslog, as these logging daemons are either already dead or will die very soon. */
log_set_target(LOG_TARGET_CONSOLE);
log_set_prohibit_ipc(true);
log_parse_environment();
r = parse_argv(argc, argv);
if (r < 0)
goto error;
/* journald will die if not gone yet. The log target defaults
* to console, but may have been changed by command line options. */
log_set_prohibit_ipc(true);
log_open();
umask(0022);
@ -306,8 +309,8 @@ int main(int argc, char *argv[]) {
else if (streq(arg_verb, "exit"))
cmd = 0; /* ignored, just checking that arg_verb is valid */
else {
r = -EINVAL;
log_error("Unknown action '%s'.", arg_verb);
r = -EINVAL;
goto error;
}
@ -324,7 +327,7 @@ int main(int argc, char *argv[]) {
}
/* Lock us into memory */
mlockall(MCL_CURRENT|MCL_FUTURE);
(void) mlockall(MCL_CURRENT|MCL_FUTURE);
/* Synchronize everything that is not written to disk yet at this point already. This is a good idea so that
* slow IO is processed here already and the final process killing spree is not impacted by processes

View 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) {
@ -406,10 +406,12 @@ static int remount_with_timeout(MountPoint *m, char *options, int *n_failed) {
r = wait_for_terminate_with_timeout(pid, DEFAULT_TIMEOUT_USEC);
if (r == -ETIMEDOUT) {
log_error_errno(errno, "Remounting '%s' - timed out, issuing SIGKILL to PID "PID_FMT".", m->path, pid);
log_error_errno(r, "Remounting '%s' timed out, issuing SIGKILL to PID " PID_FMT ".", m->path, pid);
(void) kill(pid, SIGKILL);
} else if (r < 0)
log_error_errno(r, "Failed to wait for process: %m");
} else if (r == -EPROTO)
log_error_errno(r, "Remounting '%s' failed abnormally, child process " PID_FMT " aborted or exited non-zero.", m->path, pid);
else if (r < 0)
log_error_errno(r, "Remounting '%s' failed unexpectedly, couldn't wait for child process " PID_FMT ": %m", m->path, pid);
return r;
}
@ -424,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) {
@ -446,10 +448,12 @@ static int umount_with_timeout(MountPoint *m, bool *changed) {
r = wait_for_terminate_with_timeout(pid, DEFAULT_TIMEOUT_USEC);
if (r == -ETIMEDOUT) {
log_error_errno(errno, "Unmounting '%s' - timed out, issuing SIGKILL to PID "PID_FMT".", m->path, pid);
log_error_errno(r, "Unmounting '%s' timed out, issuing SIGKILL to PID " PID_FMT ".", m->path, pid);
(void) kill(pid, SIGKILL);
} else if (r < 0)
log_error_errno(r, "Failed to wait for process: %m");
} else if (r == -EPROTO)
log_error_errno(r, "Unmounting '%s' failed abnormally, child process " PID_FMT " aborted or exited non-zero.", m->path, pid);
else if (r < 0)
log_error_errno(r, "Unmounting '%s' failed unexpectedly, couldn't wait for child process " PID_FMT ": %m", m->path, pid);
return r;
}

View 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);
}

View 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);
}

View 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);
}

View File

@ -48,22 +48,19 @@ int main(int argc, char*argv[]) {
if (streq(argv[1], "start")) {
r = unlink_or_warn("/run/nologin");
k = unlink_or_warn("/etc/nologin");
if (r < 0 || k < 0)
return EXIT_FAILURE;
if (k < 0 && r >= 0)
r = k;
} else if (streq(argv[1], "stop")) {
r = write_string_file_atomic_label("/run/nologin", "System is going down.");
if (r < 0) {
if (r < 0)
log_error_errno(r, "Failed to create /run/nologin: %m");
return EXIT_FAILURE;
}
} else {
log_error("Unknown verb %s.", argv[1]);
return EXIT_FAILURE;
log_error("Unknown verb '%s'.", argv[1]);
r = -EINVAL;
}
mac_selinux_finish();
return EXIT_SUCCESS;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}