} else
l = message;
- r = utmp_wall(l, "systemd-journald", NULL);
+ r = utmp_wall(l, "systemd-journald", NULL, NULL, NULL);
if (r < 0)
log_debug_errno(r, "Failed to send wall message: %m");
}
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;
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;
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;
int utmp_put_dead_process(const char *id, pid_t pid, int code, int status);
int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line);
-int utmp_wall(const char *message, const char *username, bool (*match_tty)(const char *tty));
+int utmp_wall(
+ const char *message,
+ const char *username,
+ const char *origin_tty,
+ bool (*match_tty)(const char *tty, void *userdata),
+ void *userdata);
#else /* HAVE_UTMP */
static inline int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line) {
return 0;
}
-static inline int utmp_wall(const char *message, const char *username,
- bool (*match_tty)(const char *tty)) {
+static inline int utmp_wall(
+ const char *message,
+ const char *username,
+ const char *origin_tty,
+ bool (*match_tty)(const char *tty, void *userdata),
+ void *userdata);
return 0;
}
if (asprintf(&l, "%s%s%s%s!", c->wall_message, c->wall_message[0] ? "\n" : "",
prefix, format_timestamp(date, sizeof(date), c->usec)) >= 0)
- utmp_wall(l, NULL, NULL);
+ utmp_wall(l, NULL, NULL, NULL, NULL);
else
log_error("Failed to allocate wall message");
}
}
if (*p) {
- utmp_wall(p, NULL, NULL);
+ utmp_wall(p, NULL, NULL, NULL, NULL);
return;
}
}
if (!table[a])
return;
- utmp_wall(table[a], NULL, NULL);
+ utmp_wall(table[a], NULL, NULL, NULL, NULL);
}
static bool avoid_bus(void) {
return fd;
}
-static bool wall_tty_match(const char *path) {
+static bool wall_tty_match(const char *path, void *userdata) {
int fd, r;
struct stat st;
_cleanup_free_ char *p = NULL;
r = q;
if (wall)
- utmp_wall(wall, NULL, wall_tty_match);
+ utmp_wall(wall, NULL, NULL, wall_tty_match, NULL);
}
return r;