]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: Make sure resolve_dev_console() always returns a full path
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 21 Mar 2025 09:36:14 +0000 (10:36 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 4 Apr 2025 15:12:58 +0000 (17:12 +0200)
Currently it returns a full path in some cases and a partial path in others.
Let's make sure it always returns a full path.

src/basic/terminal-util.c
src/core/execute.c

index 50ad4c89af309ce40ec147b30439dcf7b680d4f4..498e2d532ba612a587c693c7d5a8d7601bde9687 100644 (file)
@@ -1156,10 +1156,12 @@ int resolve_dev_console(char **ret) {
                 tty = active;
         }
 
-        if (tty != active)
-                return strdup_to(ret, tty);
+        _cleanup_free_ char *path = NULL;
+        path = path_join("/dev", tty);
+        if (!path)
+                return -ENOMEM;
 
-        *ret = TAKE_PTR(active);
+        *ret = TAKE_PTR(path);
         return 0;
 }
 
@@ -1231,9 +1233,7 @@ bool tty_is_vc_resolve(const char *tty) {
 
         assert(tty);
 
-        tty = skip_dev_prefix(tty);
-
-        if (streq(tty, "console")) {
+        if (streq(skip_dev_prefix(tty), "console")) {
                 if (resolve_dev_console(&resolved) < 0)
                         return false;
 
index 3bc80cd643643519078460da320604ae8a3b0c78..93fce15d0d99e2cc7b5bb2ee1de4e1f42135a08d 100644 (file)
@@ -970,7 +970,7 @@ static bool tty_may_match_dev_console(const char *tty) {
                 return true; /* if we could not resolve, assume it may */
 
         /* "tty0" means the active VC, so it may be the same sometimes */
-        return path_equal(resolved, tty) || (streq(resolved, "tty0") && tty_is_vc(tty));
+        return path_equal(skip_dev_prefix(resolved), tty) || (streq(skip_dev_prefix(resolved), "tty0") && tty_is_vc(tty));
 }
 
 static bool exec_context_may_touch_tty(const ExecContext *ec) {