2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-03-14 00:38:15 +01:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2016-11-07 16:14:59 +01:00
|
|
|
#include "format-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "journald-server.h"
|
2015-11-16 22:09:36 +01:00
|
|
|
#include "journald-wall.h"
|
2015-04-10 19:10:00 +02:00
|
|
|
#include "process-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "utmp-wtmp.h"
|
2014-03-14 00:38:15 +01:00
|
|
|
|
|
|
|
void server_forward_wall(
|
|
|
|
Server *s,
|
|
|
|
int priority,
|
|
|
|
const char *identifier,
|
|
|
|
const char *message,
|
2014-11-02 21:46:42 +01:00
|
|
|
const struct ucred *ucred) {
|
2014-03-14 00:38:15 +01:00
|
|
|
|
|
|
|
_cleanup_free_ char *ident_buf = NULL, *l_buf = NULL;
|
|
|
|
const char *l;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(s);
|
|
|
|
assert(message);
|
|
|
|
|
|
|
|
if (LOG_PRI(priority) > s->max_level_wall)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ucred) {
|
|
|
|
if (!identifier) {
|
|
|
|
get_process_comm(ucred->pid, &ident_buf);
|
|
|
|
identifier = ident_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(&l_buf, "%s["PID_FMT"]: %s", strempty(identifier), ucred->pid, message) < 0) {
|
|
|
|
log_oom();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = l_buf;
|
|
|
|
|
|
|
|
} else if (identifier) {
|
|
|
|
|
2016-10-23 17:43:27 +02:00
|
|
|
l = l_buf = strjoin(identifier, ": ", message);
|
2014-03-14 00:38:15 +01:00
|
|
|
if (!l_buf) {
|
|
|
|
log_oom();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
l = message;
|
|
|
|
|
2015-04-24 15:31:29 +02:00
|
|
|
r = utmp_wall(l, "systemd-journald", NULL, NULL, NULL);
|
2014-03-14 00:38:15 +01:00
|
|
|
if (r < 0)
|
2014-11-28 13:19:16 +01:00
|
|
|
log_debug_errno(r, "Failed to send wall message: %m");
|
2014-03-14 00:38:15 +01:00
|
|
|
}
|