diff options
author | Sebastian Thorarensen <sebth@naju.se> | 2014-03-14 00:38:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-14 21:27:33 +0100 |
commit | 9003d9b0d628be059922e522fd35f9c5b4d8b039 (patch) | |
tree | 3363d67fa31dcb4f83a1615eef66cdf160fb0256 /src/shared/utmp-wtmp.c | |
parent | sd-bus: don't choke if somebody sends us a message with a unix fd count of 0 (diff) | |
download | systemd-9003d9b0d628be059922e522fd35f9c5b4d8b039.tar.xz systemd-9003d9b0d628be059922e522fd35f9c5b4d8b039.zip |
utmp-wtmp: allow overriding username on wall
utmp_wall() now takes an optional argument 'username_override' which
allows the caller to override the username shown on wall messages.
journald will use this to inform users that its wall messages comes from
'systemd-journald'.
Diffstat (limited to 'src/shared/utmp-wtmp.c')
-rw-r--r-- | src/shared/utmp-wtmp.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 32996fad36..30a0c031f3 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -347,16 +347,20 @@ static int write_to_terminal(const char *tty, const char *message) { return 0; } -int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) { +int utmp_wall(const char *message, const char *username, bool (*match_tty)(const char *tty)) { _cleanup_free_ char *text = NULL, *hn = NULL, *un = NULL, *tty = NULL; char date[FORMAT_TIMESTAMP_MAX]; struct utmpx *u; int r; hn = gethostname_malloc(); - un = getlogname_malloc(); - if (!hn || !un) + if (!hn) return -ENOMEM; + if (!username) { + un = getlogname_malloc(); + if (!un) + return -ENOMEM; + } getttyname_harder(STDIN_FILENO, &tty); @@ -364,7 +368,7 @@ int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) { "\a\r\n" "Broadcast message from %s@%s%s%s (%s):\r\n\r\n" "%s\r\n\r\n", - un, hn, + un ?: username, hn, tty ? " on " : "", strempty(tty), format_timestamp(date, sizeof(date), now(CLOCK_REALTIME)), message) < 0) |