ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit da215823a36a86eaaa593098c0244e5d9e5e08bb
parent 323f6be8ef0e084a3d468d48573ab9b9e7b94f66
Author: sin <sin@2f30.org>
Date:   Tue,  3 Jun 2014 12:29:16 +0100

Inform the user if exec*() fails

Diffstat:
Msu.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/su.c b/su.c @@ -16,7 +16,7 @@ extern char **environ; static const char *randreply(void); -static void dologin(struct passwd *); +static int dologin(struct passwd *); static void usage(void) @@ -119,7 +119,7 @@ dosu: eprintf("setuid:"); if (lflag) { - dologin(pw); + return dologin(pw); } else { newargv = (char *const[]){pw->pw_shell, NULL}; if (!pflag) { @@ -136,8 +136,10 @@ dosu: setenv("PATH", ENV_PATH, 1); execve(pflag ? getenv("SHELL") : pw->pw_shell, newargv, environ); + weprintf("execve %s:", pw->pw_shell); + return (errno == ENOENT) ? 127 : 126; } - return (errno == ENOENT) ? 127 : 126; + return EXIT_SUCCESS; } static const char * @@ -160,7 +162,7 @@ randreply(void) return replies[rand() % LEN(replies)]; } -static void +static int dologin(struct passwd *pw) { char *term = getenv("TERM"); @@ -177,4 +179,6 @@ dologin(struct passwd *pw) if (chdir(pw->pw_dir) < 0) eprintf("chdir %s:", pw->pw_dir); execlp(pw->pw_shell, pw->pw_shell, "-l", NULL); + weprintf("execlp %s:", pw->pw_shell); + return (errno == ENOENT) ? 127 : 126; }