commit cf9e26d7fa2d13ede8ce2830819e311fc0dd83b9
parent 8f5a0c32362dc447ab066f9c3ad7802153a6bb40
Author: neeshy <neeshy@tfwno.gf>
Date: Mon, 12 Feb 2024 16:25:50 -0500
su: fix setting argv0
argv0 was being set to the user's login shell even when -p was
specified. Only populate newargv once the shell is properly determined.
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/su.c b/su.c
@@ -75,9 +75,6 @@ main(int argc, char *argv[])
shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell;
if (lflag) {
- newargv[0] = shell;
- newargv[1] = "-l";
- newargv[2] = NULL;
term = getenv("TERM");
clearenv();
setenv("HOME", pw->pw_dir, 1);
@@ -87,9 +84,10 @@ main(int argc, char *argv[])
setenv("TERM", term ? term : "linux", 1);
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
- } else {
newargv[0] = shell;
- newargv[1] = NULL;
+ newargv[1] = "-l";
+ newargv[2] = NULL;
+ } else {
if (pflag) {
shell = getenv("SHELL");
} else {
@@ -100,6 +98,8 @@ main(int argc, char *argv[])
setenv("LOGNAME", pw->pw_name, 1);
}
}
+ newargv[0] = shell;
+ newargv[1] = NULL;
}
if (strcmp(pw->pw_name, "root") == 0)
setenv("PATH", ENV_SUPATH, 1);