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