mirror of git://git.suckless.org/sbase
Inform the user if exec*() fails
This commit is contained in:
parent
323f6be8ef
commit
da215823a3
12
su.c
12
su.c
|
@ -16,7 +16,7 @@
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
static const char *randreply(void);
|
static const char *randreply(void);
|
||||||
static void dologin(struct passwd *);
|
static int dologin(struct passwd *);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
|
@ -119,7 +119,7 @@ dosu:
|
||||||
eprintf("setuid:");
|
eprintf("setuid:");
|
||||||
|
|
||||||
if (lflag) {
|
if (lflag) {
|
||||||
dologin(pw);
|
return dologin(pw);
|
||||||
} else {
|
} else {
|
||||||
newargv = (char *const[]){pw->pw_shell, NULL};
|
newargv = (char *const[]){pw->pw_shell, NULL};
|
||||||
if (!pflag) {
|
if (!pflag) {
|
||||||
|
@ -136,8 +136,10 @@ dosu:
|
||||||
setenv("PATH", ENV_PATH, 1);
|
setenv("PATH", ENV_PATH, 1);
|
||||||
execve(pflag ? getenv("SHELL") : pw->pw_shell,
|
execve(pflag ? getenv("SHELL") : pw->pw_shell,
|
||||||
newargv, environ);
|
newargv, environ);
|
||||||
|
weprintf("execve %s:", pw->pw_shell);
|
||||||
|
return (errno == ENOENT) ? 127 : 126;
|
||||||
}
|
}
|
||||||
return (errno == ENOENT) ? 127 : 126;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
@ -160,7 +162,7 @@ randreply(void)
|
||||||
return replies[rand() % LEN(replies)];
|
return replies[rand() % LEN(replies)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
dologin(struct passwd *pw)
|
dologin(struct passwd *pw)
|
||||||
{
|
{
|
||||||
char *term = getenv("TERM");
|
char *term = getenv("TERM");
|
||||||
|
@ -177,4 +179,6 @@ dologin(struct passwd *pw)
|
||||||
if (chdir(pw->pw_dir) < 0)
|
if (chdir(pw->pw_dir) < 0)
|
||||||
eprintf("chdir %s:", pw->pw_dir);
|
eprintf("chdir %s:", pw->pw_dir);
|
||||||
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
|
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
|
||||||
|
weprintf("execlp %s:", pw->pw_shell);
|
||||||
|
return (errno == ENOENT) ? 127 : 126;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue