chiark / gitweb /
utmp-wtmp: allow overriding username on wall
authorSebastian Thorarensen <sebth@naju.se>
Thu, 13 Mar 2014 23:38:05 +0000 (00:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Mar 2014 20:27:33 +0000 (21:27 +0100)
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'.

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 32996fad36cd711fcf03a12286742bbd35de05cd..30a0c031f3f08908de7313a62cce39f7141f3b16 100644 (file)
@@ -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)
index 5924023203e6f075cd332bbf765f3d58d8dacba1..040a16e7465f8792440a7ad6d98c5e5fe797e1ab 100644 (file)
@@ -32,4 +32,4 @@ 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, bool (*match_tty)(const char *tty));
+int utmp_wall(const char *message, const char *username, bool (*match_tty)(const char *tty));
index 8d034e6cca564857ea7d1794bcb0ecf47222fc0e..fafd9ce32eca9736055fd7d69dd32400c13e8be3 100644 (file)
@@ -143,7 +143,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);
+                utmp_wall(l, NULL, NULL);
         else
                 log_error("Failed to allocate wall message");
 }
index 254ca10c4fff75ee94a11591a378e475aef0ac15..156605d1b6a9da505fb733724cff4077307292c6 100644 (file)
@@ -257,7 +257,7 @@ static void warn_wall(enum action a) {
                 }
 
                 if (*p) {
-                        utmp_wall(p, NULL);
+                        utmp_wall(p, NULL, NULL);
                         return;
                 }
         }
@@ -265,7 +265,7 @@ static void warn_wall(enum action a) {
         if (!table[a])
                 return;
 
-        utmp_wall(table[a], NULL);
+        utmp_wall(table[a], NULL, NULL);
 }
 
 static bool avoid_bus(void) {
index 7a90e6507fb1b59b9f18e2232af39c601b81abb8..fa4d660215e72ec6eec70912e3c307fd910a05b1 100644 (file)
@@ -538,7 +538,7 @@ static int show_passwords(void) {
                 free(p);
 
                 if (wall) {
-                        utmp_wall(wall, wall_tty_match);
+                        utmp_wall(wall, NULL, wall_tty_match);
                         free(wall);
                 }
         }