mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 17:06:39 +09:00
core: Settle log target if we're going to be closing all fds
Whenever we're going to close all file descriptors, we tend to close the log and set it into open when needed mode. When this is done with the logging target set to LOG_TARGET_AUTO, we run into issues because for every logging call, we'll check if stderr is connected to the journal to determine where to send the logging message. This check obviously stops working when we close stderr, so we settle the log target before we do that so that we keep using the same logging target even after stderr is closed.
This commit is contained in:
@@ -1264,6 +1264,24 @@ LogTarget log_get_target(void) {
|
||||
return log_target;
|
||||
}
|
||||
|
||||
void log_settle_target(void) {
|
||||
|
||||
/* If we're using LOG_TARGET_AUTO and opening the log again on every single log call, we'll check if
|
||||
* stderr is attached to the journal every single log call. However, if we then close all file
|
||||
* descriptors later, that will stop working because stderr will be closed as well. To avoid that
|
||||
* problem, this function is used to permanently change the log target depending on whether stderr is
|
||||
* connected to the journal or not. */
|
||||
|
||||
LogTarget t = log_get_target();
|
||||
|
||||
if (t != LOG_TARGET_AUTO)
|
||||
return;
|
||||
|
||||
t = getpid_cached() == 1 || stderr_is_journal() ? (prohibit_ipc ? LOG_TARGET_KMSG : LOG_TARGET_JOURNAL_OR_KMSG)
|
||||
: LOG_TARGET_CONSOLE;
|
||||
log_set_target(t);
|
||||
}
|
||||
|
||||
int log_get_max_level(void) {
|
||||
return log_max_level;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user