diff options
Diffstat (limited to 'src/shared/utmp-wtmp.c')
-rw-r--r-- | src/shared/utmp-wtmp.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index bdb962af34..8f66df7718 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -21,7 +21,6 @@ #include <utmpx.h> #include <errno.h> -#include <assert.h> #include <string.h> #include <sys/utsname.h> #include <fcntl.h> @@ -30,6 +29,8 @@ #include "macro.h" #include "path-util.h" +#include "terminal-util.h" +#include "hostname-util.h" #include "utmp-wtmp.h" int utmp_get_runlevel(int *runlevel, int *previous) { @@ -347,8 +348,14 @@ static int write_to_terminal(const char *tty, const char *message) { return 0; } -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; +int utmp_wall( + const char *message, + const char *username, + const char *origin_tty, + bool (*match_tty)(const char *tty, void *userdata), + void *userdata) { + + _cleanup_free_ char *text = NULL, *hn = NULL, *un = NULL, *stdin_tty = NULL; char date[FORMAT_TIMESTAMP_MAX]; struct utmpx *u; int r; @@ -362,14 +369,17 @@ int utmp_wall(const char *message, const char *username, bool (*match_tty)(const return -ENOMEM; } - getttyname_harder(STDIN_FILENO, &tty); + if (!origin_tty) { + getttyname_harder(STDIN_FILENO, &stdin_tty); + origin_tty = stdin_tty; + } if (asprintf(&text, "\a\r\n" "Broadcast message from %s@%s%s%s (%s):\r\n\r\n" "%s\r\n\r\n", un ?: username, hn, - tty ? " on " : "", strempty(tty), + origin_tty ? " on " : "", strempty(origin_tty), format_timestamp(date, sizeof(date), now(CLOCK_REALTIME)), message) < 0) return -ENOMEM; @@ -396,7 +406,7 @@ int utmp_wall(const char *message, const char *username, bool (*match_tty)(const path = buf; } - if (!match_tty || match_tty(path)) { + if (!match_tty || match_tty(path, userdata)) { q = write_to_terminal(path, text); if (q < 0) r = q; |