| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "format-util.h" |
| 5 |
#include "journald-manager.h" |
| 6 |
#include "journald-wall.h" |
| 7 |
#include "log.h" |
| 8 |
#include "process-util.h" |
| 9 |
#include "string-util.h" |
| 10 |
#include "wall.h" |
| 11 |
|
| 12 |
void manager_forward_wall( |
| 13 |
Manager *m, |
| 14 |
int priority, |
| 15 |
const char *identifier, |
| 16 |
const char *message, |
| 17 |
const struct ucred *ucred) { |
| 18 |
|
| 19 |
_cleanup_free_ char *ident_buf = NULL, *l_buf = NULL; |
| 20 |
const char *l; |
| 21 |
int r; |
| 22 |
|
| 23 |
assert(m); |
| 24 |
assert(message); |
| 25 |
|
| 26 |
if (LOG_PRI(priority) > m->config.max_level_wall) |
| 27 |
return; |
| 28 |
|
| 29 |
if (ucred) { |
| 30 |
if (!identifier) { |
| 31 |
(void) pid_get_comm(ucred->pid, &ident_buf); |
| 32 |
identifier = ident_buf; |
| 33 |
} |
| 34 |
|
| 35 |
if (asprintf(&l_buf, "%s["PID_FMT"]: %s", strempty(identifier), ucred->pid, message) < 0) { |
| 36 |
log_oom(); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
l = l_buf; |
| 41 |
|
| 42 |
} else if (identifier) { |
| 43 |
|
| 44 |
l = l_buf = strjoin(identifier, ": ", message); |
| 45 |
if (!l_buf) { |
| 46 |
log_oom(); |
| 47 |
return; |
| 48 |
} |
| 49 |
} else |
| 50 |
l = message; |
| 51 |
|
| 52 |
r = wall(l, "systemd-journald", NULL, NULL, NULL); |
| 53 |
if (r < 0) |
| 54 |
log_debug_errno(r, "Failed to send wall message: %m"); |
| 55 |
} |