2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/signalfd.h>
29 #include <sys/socket.h>
36 #include "sd-messages.h"
38 #include "alloc-util.h"
40 #include "format-util.h"
45 #include "parse-util.h"
46 #include "proc-cmdline.h"
47 #include "process-util.h"
48 #include "signal-util.h"
49 #include "socket-util.h"
50 #include "stdio-util.h"
51 #include "string-table.h"
52 #include "string-util.h"
53 #include "syslog-util.h"
54 #include "terminal-util.h"
55 #include "time-util.h"
58 #define SNDBUF_SIZE (8*1024*1024)
60 static LogTarget log_target
= LOG_TARGET_CONSOLE
;
61 static int log_max_level
[] = {LOG_INFO
, LOG_INFO
};
62 assert_cc(ELEMENTSOF(log_max_level
) == _LOG_REALM_MAX
);
63 static int log_facility
= LOG_DAEMON
;
65 static int console_fd
= STDERR_FILENO
;
66 static int syslog_fd
= -1;
67 static int kmsg_fd
= -1;
68 static int journal_fd
= -1;
70 static bool syslog_is_stream
= false;
72 static bool show_color
= false;
73 static bool show_location
= false;
75 static bool upgrade_syslog_to_journal
= false;
76 static bool always_reopen_console
= false;
78 /* Akin to glibc's __abort_msg; which is private and we hence cannot
80 static char *log_abort_msg
= NULL
;
82 void log_close_console(void) {
87 if (getpid_cached() == 1) {
89 safe_close(console_fd
);
95 static int log_open_console(void) {
100 if (always_reopen_console
) {
101 console_fd
= open_terminal("/dev/console", O_WRONLY
|O_NOCTTY
|O_CLOEXEC
);
105 console_fd
= STDERR_FILENO
;
110 void log_close_kmsg(void) {
111 kmsg_fd
= safe_close(kmsg_fd
);
114 static int log_open_kmsg(void) {
119 kmsg_fd
= open("/dev/kmsg", O_WRONLY
|O_NOCTTY
|O_CLOEXEC
);
126 void log_close_syslog(void) {
127 syslog_fd
= safe_close(syslog_fd
);
130 static int create_log_socket(int type
) {
134 fd
= socket(AF_UNIX
, type
|SOCK_CLOEXEC
, 0);
138 (void) fd_inc_sndbuf(fd
, SNDBUF_SIZE
);
140 /* We need a blocking fd here since we'd otherwise lose
141 messages way too early. However, let's not hang forever in the
142 unlikely case of a deadlock. */
143 if (getpid_cached() == 1)
144 timeval_store(&tv
, 10 * USEC_PER_MSEC
);
146 timeval_store(&tv
, 10 * USEC_PER_SEC
);
147 (void) setsockopt(fd
, SOL_SOCKET
, SO_SNDTIMEO
, &tv
, sizeof(tv
));
152 static int log_open_syslog(void) {
154 static const union sockaddr_union sa
= {
155 .un
.sun_family
= AF_UNIX
,
156 .un
.sun_path
= "/dev/log",
164 syslog_fd
= create_log_socket(SOCK_DGRAM
);
170 if (connect(syslog_fd
, &sa
.sa
, SOCKADDR_UN_LEN(sa
.un
)) < 0) {
171 safe_close(syslog_fd
);
173 /* Some legacy syslog systems still use stream
174 * sockets. They really shouldn't. But what can we
176 syslog_fd
= create_log_socket(SOCK_STREAM
);
182 if (connect(syslog_fd
, &sa
.sa
, SOCKADDR_UN_LEN(sa
.un
)) < 0) {
187 syslog_is_stream
= true;
189 syslog_is_stream
= false;
198 void log_close_journal(void) {
199 journal_fd
= safe_close(journal_fd
);
202 static int log_open_journal(void) {
204 static const union sockaddr_union sa
= {
205 .un
.sun_family
= AF_UNIX
,
206 .un
.sun_path
= "/run/systemd/journal/socket",
214 journal_fd
= create_log_socket(SOCK_DGRAM
);
215 if (journal_fd
< 0) {
220 if (connect(journal_fd
, &sa
.sa
, SOCKADDR_UN_LEN(sa
.un
)) < 0) {
235 /* Do not call from library code. */
237 /* If we don't use the console we close it here, to not get
238 * killed by SAK. If we don't use syslog we close it here so
239 * that we are not confused by somebody deleting the socket in
240 * the fs. If we don't use /dev/kmsg we still keep it open,
241 * because there is no reason to close it. */
243 if (log_target
== LOG_TARGET_NULL
) {
250 if (!IN_SET(log_target
, LOG_TARGET_AUTO
, LOG_TARGET_SAFE
) ||
251 getpid_cached() == 1 ||
252 isatty(STDERR_FILENO
) <= 0) {
254 if (IN_SET(log_target
, LOG_TARGET_AUTO
,
255 LOG_TARGET_JOURNAL_OR_KMSG
,
256 LOG_TARGET_JOURNAL
)) {
257 r
= log_open_journal();
265 if (IN_SET(log_target
, LOG_TARGET_SYSLOG_OR_KMSG
,
266 LOG_TARGET_SYSLOG
)) {
267 r
= log_open_syslog();
275 if (IN_SET(log_target
, LOG_TARGET_AUTO
,
277 LOG_TARGET_JOURNAL_OR_KMSG
,
278 LOG_TARGET_SYSLOG_OR_KMSG
,
293 return log_open_console();
296 void log_set_target(LogTarget target
) {
298 assert(target
< _LOG_TARGET_MAX
);
300 if (upgrade_syslog_to_journal
) {
301 if (target
== LOG_TARGET_SYSLOG
)
302 target
= LOG_TARGET_JOURNAL
;
303 else if (target
== LOG_TARGET_SYSLOG_OR_KMSG
)
304 target
= LOG_TARGET_JOURNAL_OR_KMSG
;
310 void log_close(void) {
311 /* Do not call from library code. */
319 void log_forget_fds(void) {
320 /* Do not call from library code. */
322 console_fd
= kmsg_fd
= syslog_fd
= journal_fd
= -1;
325 void log_set_max_level_realm(LogRealm realm
, int level
) {
326 assert((level
& LOG_PRIMASK
) == level
);
327 assert(realm
< ELEMENTSOF(log_max_level
));
329 log_max_level
[realm
] = level
;
332 void log_set_facility(int facility
) {
333 log_facility
= facility
;
336 static int write_to_console(
342 const char *buffer
) {
344 char location
[256], prefix
[1 + DECIMAL_STR_MAX(int) + 2];
345 struct iovec iovec
[6] = {};
352 if (log_target
== LOG_TARGET_CONSOLE_PREFIXED
) {
353 xsprintf(prefix
, "<%i>", level
);
354 IOVEC_SET_STRING(iovec
[n
++], prefix
);
357 highlight
= LOG_PRI(level
) <= LOG_ERR
&& show_color
;
360 snprintf(location
, sizeof(location
), "(%s:%i) ", file
, line
);
361 IOVEC_SET_STRING(iovec
[n
++], location
);
365 IOVEC_SET_STRING(iovec
[n
++], ANSI_HIGHLIGHT_RED
);
366 IOVEC_SET_STRING(iovec
[n
++], buffer
);
368 IOVEC_SET_STRING(iovec
[n
++], ANSI_NORMAL
);
369 IOVEC_SET_STRING(iovec
[n
++], "\n");
371 if (writev(console_fd
, iovec
, n
) < 0) {
373 if (errno
== EIO
&& getpid_cached() == 1) {
375 /* If somebody tried to kick us from our
376 * console tty (via vhangup() or suchlike),
377 * try to reconnect */
385 if (writev(console_fd
, iovec
, n
) < 0)
394 static int write_to_syslog(
400 const char *buffer
) {
402 char header_priority
[2 + DECIMAL_STR_MAX(int) + 1],
404 header_pid
[4 + DECIMAL_STR_MAX(pid_t
) + 1];
405 struct iovec iovec
[5] = {};
406 struct msghdr msghdr
= {
408 .msg_iovlen
= ELEMENTSOF(iovec
),
416 xsprintf(header_priority
, "<%i>", level
);
418 t
= (time_t) (now(CLOCK_REALTIME
) / USEC_PER_SEC
);
423 if (strftime(header_time
, sizeof(header_time
), "%h %e %T ", tm
) <= 0)
426 xsprintf(header_pid
, "["PID_FMT
"]: ", getpid_cached());
428 IOVEC_SET_STRING(iovec
[0], header_priority
);
429 IOVEC_SET_STRING(iovec
[1], header_time
);
430 IOVEC_SET_STRING(iovec
[2], program_invocation_short_name
);
431 IOVEC_SET_STRING(iovec
[3], header_pid
);
432 IOVEC_SET_STRING(iovec
[4], buffer
);
434 /* When using syslog via SOCK_STREAM separate the messages by NUL chars */
435 if (syslog_is_stream
)
441 n
= sendmsg(syslog_fd
, &msghdr
, MSG_NOSIGNAL
);
445 if (!syslog_is_stream
||
446 (size_t) n
>= IOVEC_TOTAL_SIZE(iovec
, ELEMENTSOF(iovec
)))
449 IOVEC_INCREMENT(iovec
, ELEMENTSOF(iovec
), n
);
455 static int write_to_kmsg(
461 const char *buffer
) {
463 char header_priority
[2 + DECIMAL_STR_MAX(int) + 1],
464 header_pid
[4 + DECIMAL_STR_MAX(pid_t
) + 1];
465 struct iovec iovec
[5] = {};
470 xsprintf(header_priority
, "<%i>", level
);
471 xsprintf(header_pid
, "["PID_FMT
"]: ", getpid_cached());
473 IOVEC_SET_STRING(iovec
[0], header_priority
);
474 IOVEC_SET_STRING(iovec
[1], program_invocation_short_name
);
475 IOVEC_SET_STRING(iovec
[2], header_pid
);
476 IOVEC_SET_STRING(iovec
[3], buffer
);
477 IOVEC_SET_STRING(iovec
[4], "\n");
479 if (writev(kmsg_fd
, iovec
, ELEMENTSOF(iovec
)) < 0)
485 static int log_do_header(
490 const char *file
, int line
, const char *func
,
491 const char *object_field
, const char *object
,
492 const char *extra_field
, const char *extra
) {
494 snprintf(header
, size
,
496 "SYSLOG_FACILITY=%i\n"
503 "SYSLOG_IDENTIFIER=%s\n",
506 isempty(file
) ? "" : "CODE_FILE=",
507 isempty(file
) ? "" : file
,
508 isempty(file
) ? "" : "\n",
509 line
? "CODE_LINE=" : "",
510 line
? 1 : 0, line
, /* %.0d means no output too, special case for 0 */
512 isempty(func
) ? "" : "CODE_FUNC=",
513 isempty(func
) ? "" : func
,
514 isempty(func
) ? "" : "\n",
515 error
? "ERRNO=" : "",
516 error
? 1 : 0, error
,
518 isempty(object
) ? "" : object_field
,
519 isempty(object
) ? "" : object
,
520 isempty(object
) ? "" : "\n",
521 isempty(extra
) ? "" : extra_field
,
522 isempty(extra
) ? "" : extra
,
523 isempty(extra
) ? "" : "\n",
524 program_invocation_short_name
);
529 static int write_to_journal(
535 const char *object_field
,
537 const char *extra_field
,
539 const char *buffer
) {
541 char header
[LINE_MAX
];
542 struct iovec iovec
[4] = {};
543 struct msghdr mh
= {};
548 log_do_header(header
, sizeof(header
), level
, error
, file
, line
, func
, object_field
, object
, extra_field
, extra
);
550 IOVEC_SET_STRING(iovec
[0], header
);
551 IOVEC_SET_STRING(iovec
[1], "MESSAGE=");
552 IOVEC_SET_STRING(iovec
[2], buffer
);
553 IOVEC_SET_STRING(iovec
[3], "\n");
556 mh
.msg_iovlen
= ELEMENTSOF(iovec
);
558 if (sendmsg(journal_fd
, &mh
, MSG_NOSIGNAL
) < 0)
564 int log_dispatch_internal(
570 const char *object_field
,
573 const char *extra_field
,
581 if (log_target
== LOG_TARGET_NULL
)
584 /* Patch in LOG_DAEMON facility if necessary */
585 if ((level
& LOG_FACMASK
) == 0)
586 level
= log_facility
| LOG_PRI(level
);
592 buffer
+= strspn(buffer
, NEWLINE
);
597 if ((e
= strpbrk(buffer
, NEWLINE
)))
600 if (IN_SET(log_target
, LOG_TARGET_AUTO
,
601 LOG_TARGET_JOURNAL_OR_KMSG
,
602 LOG_TARGET_JOURNAL
)) {
604 k
= write_to_journal(level
, error
, file
, line
, func
, object_field
, object
, extra_field
, extra
, buffer
);
612 if (IN_SET(log_target
, LOG_TARGET_SYSLOG_OR_KMSG
,
613 LOG_TARGET_SYSLOG
)) {
615 k
= write_to_syslog(level
, error
, file
, line
, func
, buffer
);
624 IN_SET(log_target
, LOG_TARGET_AUTO
,
626 LOG_TARGET_SYSLOG_OR_KMSG
,
627 LOG_TARGET_JOURNAL_OR_KMSG
,
630 k
= write_to_kmsg(level
, error
, file
, line
, func
, buffer
);
638 (void) write_to_console(level
, error
, file
, line
, func
, buffer
);
646 int log_dump_internal(
654 LogRealm realm
= LOG_REALM_REMOVE_LEVEL(level
);
657 /* This modifies the buffer... */
662 if (_likely_(LOG_PRI(level
) > log_max_level
[realm
]))
665 return log_dispatch_internal(level
, error
, file
, line
, func
, NULL
, NULL
, NULL
, NULL
, buffer
);
668 int log_internalv_realm(
677 LogRealm realm
= LOG_REALM_REMOVE_LEVEL(level
);
678 char buffer
[LINE_MAX
];
684 if (_likely_(LOG_PRI(level
) > log_max_level
[realm
]))
687 /* Make sure that %m maps to the specified error */
691 vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
693 return log_dispatch_internal(level
, error
, file
, line
, func
, NULL
, NULL
, NULL
, NULL
, buffer
);
696 int log_internal_realm(
702 const char *format
, ...) {
707 va_start(ap
, format
);
708 r
= log_internalv_realm(level
, error
, file
, line
, func
, format
, ap
);
714 int log_object_internalv(
720 const char *object_field
,
722 const char *extra_field
,
733 if (_likely_(LOG_PRI(level
) > log_max_level
[LOG_REALM_SYSTEMD
]))
736 /* Make sure that %m maps to the specified error */
740 /* Prepend the object name before the message */
745 buffer
= newa(char, n
+ 2 + LINE_MAX
);
746 b
= stpcpy(stpcpy(buffer
, object
), ": ");
748 b
= buffer
= newa(char, LINE_MAX
);
750 vsnprintf(b
, LINE_MAX
, format
, ap
);
752 return log_dispatch_internal(level
, error
, file
, line
, func
,
753 object_field
, object
, extra_field
, extra
, buffer
);
756 int log_object_internal(
762 const char *object_field
,
764 const char *extra_field
,
766 const char *format
, ...) {
771 va_start(ap
, format
);
772 r
= log_object_internalv(level
, error
, file
, line
, func
, object_field
, object
, extra_field
, extra
, format
, ap
);
778 static void log_assert(
784 const char *format
) {
786 static char buffer
[LINE_MAX
];
787 LogRealm realm
= LOG_REALM_REMOVE_LEVEL(level
);
789 if (_likely_(LOG_PRI(level
) > log_max_level
[realm
]))
792 DISABLE_WARNING_FORMAT_NONLITERAL
;
793 snprintf(buffer
, sizeof buffer
, format
, text
, file
, line
, func
);
796 log_abort_msg
= buffer
;
798 log_dispatch_internal(level
, 0, file
, line
, func
, NULL
, NULL
, NULL
, NULL
, buffer
);
801 noreturn
void log_assert_failed_realm(
808 log_assert(LOG_REALM_PLUS_LEVEL(realm
, LOG_CRIT
), text
, file
, line
, func
,
809 "Assertion '%s' failed at %s:%u, function %s(). Aborting.");
813 noreturn
void log_assert_failed_unreachable_realm(
820 log_assert(LOG_REALM_PLUS_LEVEL(realm
, LOG_CRIT
), text
, file
, line
, func
,
821 "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
825 void log_assert_failed_return_realm(
832 log_assert(LOG_REALM_PLUS_LEVEL(realm
, LOG_DEBUG
), text
, file
, line
, func
,
833 "Assertion '%s' failed at %s:%u, function %s(). Ignoring.");
836 int log_oom_internal(LogRealm realm
, const char *file
, int line
, const char *func
) {
837 log_internal_realm(LOG_REALM_PLUS_LEVEL(realm
, LOG_ERR
),
838 ENOMEM
, file
, line
, func
, "Out of memory.");
842 int log_format_iovec(
846 bool newline_separator
,
851 static const char nl
= '\n';
853 while (format
&& *n
+ 1 < iovec_len
) {
858 /* We need to copy the va_list structure,
859 * since vasprintf() leaves it afterwards at
860 * an undefined location */
866 r
= vasprintf(&m
, format
, aq
);
871 /* Now, jump enough ahead, so that we point to
872 * the next format string */
873 VA_FORMAT_ADVANCE(format
, ap
);
875 IOVEC_SET_STRING(iovec
[(*n
)++], m
);
877 if (newline_separator
) {
878 iovec
[*n
].iov_base
= (char*) &nl
;
879 iovec
[*n
].iov_len
= 1;
883 format
= va_arg(ap
, char *);
888 int log_struct_internal(
894 const char *format
, ...) {
898 LogRealm realm
= LOG_REALM_REMOVE_LEVEL(level
);
905 if (_likely_(LOG_PRI(level
) > log_max_level
[realm
]))
908 if (log_target
== LOG_TARGET_NULL
)
911 if ((level
& LOG_FACMASK
) == 0)
912 level
= log_facility
| LOG_PRI(level
);
914 if (IN_SET(log_target
, LOG_TARGET_AUTO
,
915 LOG_TARGET_JOURNAL_OR_KMSG
,
916 LOG_TARGET_JOURNAL
) &&
918 char header
[LINE_MAX
];
919 struct iovec iovec
[17] = {};
925 bool fallback
= false;
927 /* If the journal is available do structured logging */
928 log_do_header(header
, sizeof(header
), level
, error
, file
, line
, func
, NULL
, NULL
, NULL
, NULL
);
929 IOVEC_SET_STRING(iovec
[n
++], header
);
931 va_start(ap
, format
);
932 r
= log_format_iovec(iovec
, ELEMENTSOF(iovec
), &n
, true, error
, format
, ap
);
937 (void) sendmsg(journal_fd
, &mh
, MSG_NOSIGNAL
);
941 for (i
= 1; i
< n
; i
+= 2)
942 free(iovec
[i
].iov_base
);
948 /* Fallback if journal logging is not available or didn't work. */
950 va_start(ap
, format
);
958 vsnprintf(buf
, sizeof(buf
), format
, aq
);
961 if (startswith(buf
, "MESSAGE=")) {
966 VA_FORMAT_ADVANCE(format
, ap
);
968 format
= va_arg(ap
, char *);
975 return log_dispatch_internal(level
, error
, file
, line
, func
, NULL
, NULL
, NULL
, NULL
, buf
+ 8);
978 int log_set_target_from_string(const char *e
) {
981 t
= log_target_from_string(e
);
989 int log_set_max_level_from_string_realm(LogRealm realm
, const char *e
) {
992 t
= log_level_from_string(e
);
996 log_set_max_level_realm(realm
, t
);
1000 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
1003 * The systemd.log_xyz= settings are parsed by all tools, and
1006 * However, "quiet" is only parsed by PID 1, and only turns of
1007 * status output to /dev/console, but does not alter the log
1011 if (streq(key
, "debug") && !value
)
1012 log_set_max_level(LOG_DEBUG
);
1014 else if (proc_cmdline_key_streq(key
, "systemd.log_target")) {
1016 if (proc_cmdline_value_missing(key
, value
))
1019 if (log_set_target_from_string(value
) < 0)
1020 log_warning("Failed to parse log target '%s'. Ignoring.", value
);
1022 } else if (proc_cmdline_key_streq(key
, "systemd.log_level")) {
1024 if (proc_cmdline_value_missing(key
, value
))
1027 if (log_set_max_level_from_string(value
) < 0)
1028 log_warning("Failed to parse log level '%s'. Ignoring.", value
);
1030 } else if (proc_cmdline_key_streq(key
, "systemd.log_color")) {
1032 if (log_show_color_from_string(value
?: "1") < 0)
1033 log_warning("Failed to parse log color setting '%s'. Ignoring.", value
);
1035 } else if (proc_cmdline_key_streq(key
, "systemd.log_location")) {
1037 if (log_show_location_from_string(value
?: "1") < 0)
1038 log_warning("Failed to parse log location setting '%s'. Ignoring.", value
);
1044 void log_parse_environment_realm(LogRealm realm
) {
1045 /* Do not call from library code. */
1049 if (get_ctty_devnr(0, NULL
) < 0)
1050 /* Only try to read the command line in daemons. We assume that anything that has a controlling tty is
1052 (void) proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, PROC_CMDLINE_STRIP_RD_PREFIX
);
1054 e
= getenv("SYSTEMD_LOG_TARGET");
1055 if (e
&& log_set_target_from_string(e
) < 0)
1056 log_warning("Failed to parse log target '%s'. Ignoring.", e
);
1058 e
= getenv("SYSTEMD_LOG_LEVEL");
1059 if (e
&& log_set_max_level_from_string_realm(realm
, e
) < 0)
1060 log_warning("Failed to parse log level '%s'. Ignoring.", e
);
1062 e
= getenv("SYSTEMD_LOG_COLOR");
1063 if (e
&& log_show_color_from_string(e
) < 0)
1064 log_warning("Failed to parse bool '%s'. Ignoring.", e
);
1066 e
= getenv("SYSTEMD_LOG_LOCATION");
1067 if (e
&& log_show_location_from_string(e
) < 0)
1068 log_warning("Failed to parse bool '%s'. Ignoring.", e
);
1071 LogTarget
log_get_target(void) {
1075 int log_get_max_level_realm(LogRealm realm
) {
1076 return log_max_level
[realm
];
1079 void log_show_color(bool b
) {
1083 bool log_get_show_color(void) {
1087 void log_show_location(bool b
) {
1091 bool log_get_show_location(void) {
1092 return show_location
;
1095 int log_show_color_from_string(const char *e
) {
1098 t
= parse_boolean(e
);
1106 int log_show_location_from_string(const char *e
) {
1109 t
= parse_boolean(e
);
1113 log_show_location(t
);
1117 bool log_on_console(void) {
1118 if (IN_SET(log_target
, LOG_TARGET_CONSOLE
,
1119 LOG_TARGET_CONSOLE_PREFIXED
))
1122 return syslog_fd
< 0 && kmsg_fd
< 0 && journal_fd
< 0;
1125 static const char *const log_target_table
[_LOG_TARGET_MAX
] = {
1126 [LOG_TARGET_CONSOLE
] = "console",
1127 [LOG_TARGET_CONSOLE_PREFIXED
] = "console-prefixed",
1128 [LOG_TARGET_KMSG
] = "kmsg",
1129 [LOG_TARGET_JOURNAL
] = "journal",
1130 [LOG_TARGET_JOURNAL_OR_KMSG
] = "journal-or-kmsg",
1131 [LOG_TARGET_SYSLOG
] = "syslog",
1132 [LOG_TARGET_SYSLOG_OR_KMSG
] = "syslog-or-kmsg",
1133 [LOG_TARGET_AUTO
] = "auto",
1134 [LOG_TARGET_SAFE
] = "safe",
1135 [LOG_TARGET_NULL
] = "null"
1138 DEFINE_STRING_TABLE_LOOKUP(log_target
, LogTarget
);
1140 void log_received_signal(int level
, const struct signalfd_siginfo
*si
) {
1141 if (si
->ssi_pid
> 0) {
1142 _cleanup_free_
char *p
= NULL
;
1144 get_process_comm(si
->ssi_pid
, &p
);
1147 "Received SIG%s from PID %"PRIu32
" (%s).",
1148 signal_to_string(si
->ssi_signo
),
1149 si
->ssi_pid
, strna(p
));
1153 signal_to_string(si
->ssi_signo
));
1157 void log_set_upgrade_syslog_to_journal(bool b
) {
1158 upgrade_syslog_to_journal
= b
;
1161 int log_syntax_internal(
1164 const char *config_file
,
1165 unsigned config_line
,
1170 const char *format
, ...) {
1173 char buffer
[LINE_MAX
];
1175 const char *unit_fmt
= NULL
;
1180 if (_likely_(LOG_PRI(level
) > log_max_level
[LOG_REALM_SYSTEMD
]))
1183 if (log_target
== LOG_TARGET_NULL
)
1189 va_start(ap
, format
);
1190 vsnprintf(buffer
, sizeof(buffer
), format
, ap
);
1194 unit_fmt
= getpid_cached() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
1196 return log_struct_internal(
1197 LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD
, level
),
1200 "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR
,
1201 "CONFIG_FILE=%s", config_file
,
1202 "CONFIG_LINE=%u", config_line
,
1203 LOG_MESSAGE("%s:%u: %s", config_file
, config_line
, buffer
),
1208 void log_set_always_reopen_console(bool b
) {
1209 always_reopen_console
= b
;