]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: Always call chdir after chroot
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 7 Apr 2026 18:33:30 +0000 (20:33 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 7 Apr 2026 18:33:30 +0000 (20:33 +0200)
Since chroot only changes the root directory but not current working
directory, change the current working directory as well. This rebases
all possible future relative paths into the chroot environment as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
term-utils/agetty.c

index 0ce8fca61a7c06a2882bb330b90999a014a8da11..d9291858cb7e363a58aadf64a80d8f6e294c86ee 100644 (file)
@@ -560,9 +560,14 @@ int main(int argc, char **argv)
 
        login_argv[login_argc] = NULL;  /* last login argv */
 
-       if (options.chroot && chroot(options.chroot) < 0)
-               log_err(_("%s: can't change root directory %s: %m"),
-                       options.tty, options.chroot);
+       if (options.chroot) {
+               if (chroot(options.chroot) < 0)
+                       log_err(_("%s: can't change root directory %s: %m"),
+                               options.tty, options.chroot);
+               if (chdir("/") < 0)
+                       log_err(_("%s: can't change working directory %s: %m"),
+                               options.tty, "/");
+       }
        if (options.chdir && chdir(options.chdir) < 0)
                log_err(_("%s: can't change working directory %s: %m"),
                        options.tty, options.chdir);