utmp

simple login manager
git clone git://git.suckless.org/utmp
Log | Files | Refs | README | LICENSE

commit 4a855c000f1d300a44c784ed88d78a11d41cdca7
parent 9631182347109af70cc725aabd6d567c83e989ec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Aug 2014 20:08:22 +0200

Launch a login shell

Since we are creating a utmp entry, it is logical to create a login
shell

Diffstat:
utmp.c | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/utmp.c b/utmp.c @@ -38,8 +38,10 @@ int main(int argc, char *argv[]) { int status; + size_t len; uid_t uid; sigset_t set; + char *p, argv0[FILENAME_MAX], *sh; extern void addutmp(void), delutmp(void); egid = getegid(); @@ -59,15 +61,23 @@ main(int argc, char *argv[]) setenv("SHELL", pw->pw_shell, 1); setenv("HOME", pw->pw_dir, 1); + if ((p = strrchr(pw->pw_shell, '/')) == NULL) + die("incorrect shell field of passwd"); + if ((len = strlen(++p)) > sizeof(argv0) - 2) + die("shell name too long"); + argv0[0] = '-'; + memcpy(&argv0[1], p, len); + sigfillset(&set); sigprocmask(SIG_BLOCK, &set, NULL); switch (fork()) { case 0: sigprocmask(SIG_UNBLOCK, &set, NULL); - argv[0] = getenv("SHELL"); - execv(argv[0], argv); - die("error executing shell:%s", strerror(errno)); + sh = pw->pw_shell; + argv[0] = argv0; + execv(sh, argv); + die("error executing shell(%s):%s", sh, strerror(errno)); case -1: die("error spawning child:%s", strerror(errno)); default: