]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
utmp: remove /dev from line
authorVincent Bernat <vincent@bernat.ch>
Mon, 18 Oct 2021 18:58:43 +0000 (20:58 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 19 Oct 2021 07:21:54 +0000 (09:21 +0200)
utmp(5) says `ut_line` is the device name minus the leading "/dev/". Therefore,
remove it. Without that, when using UtmpMode=user, we get `/dev/tty` in the
output of `last`/`w`.

src/core/execute.c

index e1f8d9a31b87b0526f6529920453a4fb932a4c6c..9d100889018da4e7311607ab6ea46e9fad2ea88c 100644 (file)
@@ -4136,13 +4136,17 @@ static int exec_child(
                 }
         }
 
-        if (context->utmp_id)
+        if (context->utmp_id) {
+                const char *line = context->tty_path ?
+                        (path_startswith(context->tty_path, "/dev/") ?: context->tty_path) :
+                        NULL;
                 utmp_put_init_process(context->utmp_id, getpid_cached(), getsid(0),
-                                      context->tty_path,
+                                      line,
                                       context->utmp_mode == EXEC_UTMP_INIT  ? INIT_PROCESS :
                                       context->utmp_mode == EXEC_UTMP_LOGIN ? LOGIN_PROCESS :
                                       USER_PROCESS,
                                       username);
+        }
 
         if (uid_is_valid(uid)) {
                 r = chown_terminal(STDIN_FILENO, uid);