]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/utmp-wtmp: add parameter for origin tty and callback userdata
authorDaniel Mack <daniel@zonque.org>
Fri, 24 Apr 2015 13:31:29 +0000 (15:31 +0200)
committerDaniel Mack <daniel@zonque.org>
Fri, 24 Apr 2015 15:48:12 +0000 (17:48 +0200)
Instead of looking up the tty from STDIN, let utmp_wall() take an argument
to specify an origin tty for the wall message. Only if that argument is
NULL do the STDIN lookup.

Also add an void *userdata argument that is handed back to the callback
function.

src/journal/journald-wall.c
src/shared/utmp-wtmp.c
src/shared/utmp-wtmp.h
src/shutdownd/shutdownd.c
src/systemctl/systemctl.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index 5298e45be9502865e5e0724afede3c03aa6f4db2..7863766ae7f689d67f67535ac64b70aae54afbdb 100644 (file)
@@ -65,7 +65,7 @@ void server_forward_wall(
         } 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");
 }
index d6c4cc81b32847c815997bc5609b2c2eb1d6eb05..aaf249dd20b634d4e5052daa87b2b51bd4290aed 100644 (file)
@@ -347,8 +347,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 +368,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 +405,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;
index 87d004e615f78fd433abf110dc4644c0cb9240af..6ac2c7b1c768cbade799e948c4d1ae1d83188852 100644 (file)
@@ -33,7 +33,12 @@ int utmp_put_runlevel(int runlevel, int previous);
 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 */
 
@@ -55,8 +60,12 @@ static inline int utmp_put_dead_process(const char *id, pid_t pid, int code, int
 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;
 }
 
index a05cddceb2e1ac821d36cb31b192e39ca0fa76a4..8b857b55cb547c0fc1b4d5e7fbf8d583e31cc206 100644 (file)
@@ -142,7 +142,7 @@ static void warn_wall(usec_t n, struct sd_shutdown_command *c) {
 
         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");
 }
index 4e702fb8bc13f09bf6422b2cdbf896dad70e803d..38d15ff4ed2fb25399a6501ab1f6eb0809d0e667 100644 (file)
@@ -251,7 +251,7 @@ static void warn_wall(enum action a) {
                 }
 
                 if (*p) {
-                        utmp_wall(p, NULL, NULL);
+                        utmp_wall(p, NULL, NULL, NULL, NULL);
                         return;
                 }
         }
@@ -259,7 +259,7 @@ static void warn_wall(enum action a) {
         if (!table[a])
                 return;
 
-        utmp_wall(table[a], NULL, NULL);
+        utmp_wall(table[a], NULL, NULL, NULL, NULL);
 }
 
 static bool avoid_bus(void) {
index 8cd6cabb185278726a855d983095289e767f1ab0..c440170f950a75092a3d1946838300a52352e37d 100644 (file)
@@ -381,7 +381,7 @@ static int wall_tty_block(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;
@@ -455,7 +455,7 @@ static int show_passwords(void) {
                         r = q;
 
                 if (wall)
-                        utmp_wall(wall, NULL, wall_tty_match);
+                        utmp_wall(wall, NULL, NULL, wall_tty_match, NULL);
         }
 
         return r;