From: Tobias Stoeckmann Date: Tue, 7 Apr 2026 18:33:30 +0000 (+0200) Subject: agetty: Always call chdir after chroot X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e966f2e93c1c4e4b43e34ae1bfdebe728efb04f8;p=thirdparty%2Futil-linux.git agetty: Always call chdir after chroot 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 --- diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 0ce8fca61..d9291858c 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -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);