mirror of
https://github.com/troglobit/finit.git
synced 2026-10-19 11:09:35 +00:00
sulogin: minor refactor, splice out sh() as separate function
- splice out sh() as a separate function - make sh() session leader and set controlling TTY (TIOCSCTTY) to make it a proper login shell with Ctrl-C functionality - simplify call to execl() Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
a28d5b3c09
commit
86707c1f0b
1 file changed
+15
-9
+15
-9
@@ -30,6 +30,7 @@
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* getpwnam() cannot be used when statically linked */
|
||||
static int get_passwd(struct passwd *pw)
|
||||
@@ -109,6 +110,19 @@ static void freepw(struct passwd *pw)
|
||||
free(pw->pw_name);
|
||||
}
|
||||
|
||||
static int sh(void)
|
||||
{
|
||||
/*
|
||||
* Become session leader and set controlling TTY
|
||||
* to enable Ctrl-C and job control in shell.
|
||||
*/
|
||||
setsid();
|
||||
ioctl(STDIN_FILENO, TIOCSCTTY, 1);
|
||||
setenv("PS1", "# ", 1);
|
||||
|
||||
return execl(_PATH_BSHELL, "-sh", NULL);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct termios old, raw;
|
||||
@@ -156,18 +170,10 @@ int main(void)
|
||||
|
||||
passwd = crypt(pwd, pw.pw_passwd);
|
||||
if (passwd && !strcmp(passwd, pw.pw_passwd)) {
|
||||
char arg0[strlen(_PATH_BSHELL) + 2];
|
||||
char *args[2] = {
|
||||
arg0,
|
||||
NULL
|
||||
};
|
||||
|
||||
tcsetattr(1, TCSANOW, &old); /* restore tty */
|
||||
freepw(&pw);
|
||||
snprintf(arg0, sizeof(arg0), "-%s", _PATH_BSHELL);
|
||||
setenv("PS1", "# ", 1);
|
||||
|
||||
return execv(_PATH_BSHELL, args);
|
||||
return sh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user