1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

Merge pull request #8025 from sourcejedi/pid1_journal_or2

pid1: when we can't log to journal, remember our fallback log target
This commit is contained in:
Lennart Poettering 2018-01-28 11:02:24 +01:00 committed by GitHub
commit dcfb4b6103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 23 deletions

View File

@ -83,35 +83,34 @@ static bool prohibit_ipc = false;
* use here. */ * use here. */
static char *log_abort_msg = NULL; static char *log_abort_msg = NULL;
void log_close_console(void) { static void log_close_console(void) {
if (console_fd < 0) if (console_fd < 0)
return; return;
if (getpid_cached() == 1) { if (console_fd >= 3)
if (console_fd >= 3) safe_close(console_fd);
safe_close(console_fd);
console_fd = -1; console_fd = -1;
}
} }
static int log_open_console(void) { static int log_open_console(void) {
if (console_fd >= 0) if (!always_reopen_console) {
console_fd = STDERR_FILENO;
return 0; return 0;
}
if (always_reopen_console) { if (console_fd < 3) {
console_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); console_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
if (console_fd < 0) if (console_fd < 0)
return console_fd; return console_fd;
} else }
console_fd = STDERR_FILENO;
return 0; return 0;
} }
void log_close_kmsg(void) { static void log_close_kmsg(void) {
kmsg_fd = safe_close(kmsg_fd); kmsg_fd = safe_close(kmsg_fd);
} }
@ -127,7 +126,7 @@ static int log_open_kmsg(void) {
return 0; return 0;
} }
void log_close_syslog(void) { static void log_close_syslog(void) {
syslog_fd = safe_close(syslog_fd); syslog_fd = safe_close(syslog_fd);
} }
@ -199,7 +198,7 @@ fail:
return r; return r;
} }
void log_close_journal(void) { static void log_close_journal(void) {
journal_fd = safe_close(journal_fd); journal_fd = safe_close(journal_fd);
} }
@ -241,7 +240,8 @@ int log_open(void) {
/* If we don't use the console we close it here, to not get /* If we don't use the console we close it here, to not get
* killed by SAK. If we don't use syslog we close it here so * killed by SAK. If we don't use syslog we close it here so
* that we are not confused by somebody deleting the socket in * that we are not confused by somebody deleting the socket in
* the fs. If we don't use /dev/kmsg we still keep it open, * the fs, and to make sure we don't use it if prohibit_ipc is
* set. If we don't use /dev/kmsg we still keep it open,
* because there is no reason to close it. */ * because there is no reason to close it. */
if (log_target == LOG_TARGET_NULL) { if (log_target == LOG_TARGET_NULL) {

View File

@ -94,11 +94,6 @@ int log_open(void);
void log_close(void); void log_close(void);
void log_forget_fds(void); void log_forget_fds(void);
void log_close_syslog(void);
void log_close_journal(void);
void log_close_kmsg(void);
void log_close_console(void);
void log_parse_environment_realm(LogRealm realm); void log_parse_environment_realm(LogRealm realm);
#define log_parse_environment() \ #define log_parse_environment() \
log_parse_environment_realm(LOG_REALM) log_parse_environment_realm(LOG_REALM)

View File

@ -2392,7 +2392,6 @@ int main(int argc, char *argv[]) {
/* Running inside a container, as PID 1 */ /* Running inside a container, as PID 1 */
arg_system = true; arg_system = true;
log_set_target(LOG_TARGET_CONSOLE); log_set_target(LOG_TARGET_CONSOLE);
log_close_console(); /* force reopen of /dev/console */
log_open(); log_open();
/* For later on, see above... */ /* For later on, see above... */

View File

@ -3543,14 +3543,13 @@ void manager_recheck_journal(Manager *m) {
/* The journal is fully and entirely up? If so, let's permit logging to it, if that's configured. */ /* The journal is fully and entirely up? If so, let's permit logging to it, if that's configured. */
log_set_prohibit_ipc(false); log_set_prohibit_ipc(false);
log_open();
} else { } else {
/* If the journal is down, don't ever log to it, otherwise we might end up deadlocking ourselves as we /* If the journal is down, don't ever log to it, otherwise we might end up deadlocking ourselves as we
* might trigger an activation ourselves we can't fulfill */ * might trigger an activation ourselves we can't fulfill */
log_set_prohibit_ipc(true); log_set_prohibit_ipc(true);
log_close_journal();
} }
log_open();
} }
void manager_set_show_status(Manager *m, ShowStatus mode) { void manager_set_show_status(Manager *m, ShowStatus mode) {

View File

@ -284,7 +284,7 @@ int main(int argc, char *argv[]) {
/* journald will die if not gone yet. The log target defaults /* journald will die if not gone yet. The log target defaults
* to console, but may have been changed by command line options. */ * to console, but may have been changed by command line options. */
log_close_console(); /* force reopen of /dev/console */ log_set_prohibit_ipc(true);
log_open(); log_open();
umask(0022); umask(0022);