terminal-util: Make sure resolve_dev_console() always returns a full path

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.
This commit is contained in:
Daan De Meyer
2025-04-04 17:12:58 +02:00
parent 7dce799f5c
commit c7f7d87db5
2 changed files with 7 additions and 7 deletions
+6 -6
View 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;
+1 -1
View 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) {