]>
Commit | Line | Data |
---|---|---|
40b71e89 ST |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2014 Sebastian Thorarensen | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include "utmp-wtmp.h" | |
23 | #include "journald-server.h" | |
24 | #include "journald-wall.h" | |
25 | ||
26 | void server_forward_wall( | |
27 | Server *s, | |
28 | int priority, | |
29 | const char *identifier, | |
30 | const char *message, | |
31 | struct ucred *ucred) { | |
32 | ||
33 | _cleanup_free_ char *ident_buf = NULL, *l_buf = NULL; | |
34 | const char *l; | |
35 | int r; | |
36 | ||
37 | assert(s); | |
38 | assert(message); | |
39 | ||
40 | if (LOG_PRI(priority) > s->max_level_wall) | |
41 | return; | |
42 | ||
43 | if (ucred) { | |
44 | if (!identifier) { | |
45 | get_process_comm(ucred->pid, &ident_buf); | |
46 | identifier = ident_buf; | |
47 | } | |
48 | ||
49 | if (asprintf(&l_buf, "%s["PID_FMT"]: %s", strempty(identifier), ucred->pid, message) < 0) { | |
50 | log_oom(); | |
51 | return; | |
52 | } | |
53 | ||
54 | l = l_buf; | |
55 | ||
56 | } else if (identifier) { | |
57 | ||
58 | l = l_buf = strjoin(identifier, ": ", message, NULL); | |
59 | if (!l_buf) { | |
60 | log_oom(); | |
61 | return; | |
62 | } | |
63 | } else | |
64 | l = message; | |
65 | ||
66 | r = utmp_wall(l, "systemd-journald", NULL); | |
67 | if (r < 0) | |
68 | log_debug("Failed to send wall message: %s", strerror(-r)); | |
69 | } |