mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
log: add common helper log_set_target_and_open()
quite often we want to set a log target and immediately open it. Add a common helper for that.
This commit is contained in:
parent
05dd602e50
commit
1e344c1dc7
@ -347,6 +347,11 @@ void log_set_target(LogTarget target) {
|
||||
log_target = target;
|
||||
}
|
||||
|
||||
void log_set_target_and_open(LogTarget target) {
|
||||
log_set_target(target);
|
||||
log_open();
|
||||
}
|
||||
|
||||
void log_close(void) {
|
||||
/* Do not call from library code. */
|
||||
|
||||
|
@ -51,6 +51,7 @@ static inline void clear_log_syntax_callback(dummy_t *dummy) {
|
||||
const char *log_target_to_string(LogTarget target) _const_;
|
||||
LogTarget log_target_from_string(const char *s) _pure_;
|
||||
void log_set_target(LogTarget target);
|
||||
void log_set_target_and_open(LogTarget target);
|
||||
int log_set_target_from_string(const char *e);
|
||||
LogTarget log_get_target(void) _pure_;
|
||||
|
||||
|
@ -2787,8 +2787,7 @@ int main(int argc, char *argv[]) {
|
||||
if (detect_container() <= 0) {
|
||||
|
||||
/* Running outside of a container as PID 1 */
|
||||
log_set_target(LOG_TARGET_KMSG);
|
||||
log_open();
|
||||
log_set_target_and_open(LOG_TARGET_KMSG);
|
||||
|
||||
if (in_initrd())
|
||||
initrd_timestamp = userspace_timestamp;
|
||||
@ -2832,8 +2831,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
} else {
|
||||
/* Running inside a container, as PID 1 */
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_open();
|
||||
log_set_target_and_open(LOG_TARGET_CONSOLE);
|
||||
|
||||
/* For later on, see above... */
|
||||
log_set_target(LOG_TARGET_JOURNAL);
|
||||
@ -2880,8 +2878,7 @@ int main(int argc, char *argv[]) {
|
||||
/* Running as user instance */
|
||||
arg_system = false;
|
||||
log_set_always_reopen_console(true);
|
||||
log_set_target(LOG_TARGET_AUTO);
|
||||
log_open();
|
||||
log_set_target_and_open(LOG_TARGET_AUTO);
|
||||
|
||||
/* clear the kernel timestamp, because we are not PID 1 */
|
||||
kernel_timestamp = DUAL_TIMESTAMP_NULL;
|
||||
|
@ -1486,11 +1486,9 @@ static int process_kernel(int argc, char* argv[]) {
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
if (!context.is_journald) {
|
||||
if (!context.is_journald)
|
||||
/* OK, now we know it's not the journal, hence we can make use of it now. */
|
||||
log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
|
||||
log_open();
|
||||
}
|
||||
log_set_target_and_open(LOG_TARGET_JOURNAL_OR_KMSG);
|
||||
|
||||
/* If this is PID 1 disable coredump collection, we'll unlikely be able to process
|
||||
* it later on.
|
||||
@ -1589,8 +1587,7 @@ static int run(int argc, char *argv[]) {
|
||||
/* First, log to a safe place, since we don't know what crashed and it might
|
||||
* be journald which we'd rather not log to then. */
|
||||
|
||||
log_set_target(LOG_TARGET_KMSG);
|
||||
log_open();
|
||||
log_set_target_and_open(LOG_TARGET_KMSG);
|
||||
|
||||
/* Make sure we never enter a loop */
|
||||
(void) prctl(PR_SET_DUMPABLE, 0);
|
||||
|
@ -86,8 +86,7 @@ int bus_property_set_log_target(
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t);
|
||||
|
||||
log_info("Setting log target to %s.", log_target_to_string(target));
|
||||
log_set_target(target);
|
||||
log_open();
|
||||
log_set_target_and_open(target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user