]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
40b71e89 | 2 | |
b5efdb8a | 3 | #include "alloc-util.h" |
f97b34a6 | 4 | #include "format-util.h" |
07630cea | 5 | #include "journald-server.h" |
cf0fbc49 | 6 | #include "journald-wall.h" |
0b452006 | 7 | #include "process-util.h" |
07630cea LP |
8 | #include "string-util.h" |
9 | #include "utmp-wtmp.h" | |
40b71e89 ST |
10 | |
11 | void server_forward_wall( | |
12 | Server *s, | |
13 | int priority, | |
14 | const char *identifier, | |
15 | const char *message, | |
3b3154df | 16 | const struct ucred *ucred) { |
40b71e89 ST |
17 | |
18 | _cleanup_free_ char *ident_buf = NULL, *l_buf = NULL; | |
19 | const char *l; | |
20 | int r; | |
21 | ||
22 | assert(s); | |
23 | assert(message); | |
24 | ||
25 | if (LOG_PRI(priority) > s->max_level_wall) | |
26 | return; | |
27 | ||
28 | if (ucred) { | |
29 | if (!identifier) { | |
30 | get_process_comm(ucred->pid, &ident_buf); | |
31 | identifier = ident_buf; | |
32 | } | |
33 | ||
34 | if (asprintf(&l_buf, "%s["PID_FMT"]: %s", strempty(identifier), ucred->pid, message) < 0) { | |
35 | log_oom(); | |
36 | return; | |
37 | } | |
38 | ||
39 | l = l_buf; | |
40 | ||
41 | } else if (identifier) { | |
42 | ||
605405c6 | 43 | l = l_buf = strjoin(identifier, ": ", message); |
40b71e89 ST |
44 | if (!l_buf) { |
45 | log_oom(); | |
46 | return; | |
47 | } | |
48 | } else | |
49 | l = message; | |
50 | ||
99f710dd | 51 | r = utmp_wall(l, "systemd-journald", NULL, NULL, NULL); |
40b71e89 | 52 | if (r < 0) |
da927ba9 | 53 | log_debug_errno(r, "Failed to send wall message: %m"); |
40b71e89 | 54 | } |