Skip to content

Commit

Permalink
user-init.c: redirect stdin to /dev/null and start a login shell
Browse files Browse the repository at this point in the history
Signed-off-by: Anna (navi) Figueiredo Gomes <[email protected]>
  • Loading branch information
navi-desu committed Jul 22, 2024
1 parent 5824e26 commit 91102b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/user_init/user_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <grp.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

#include "helpers.h"
#include "rc.h"
Expand All @@ -12,6 +13,7 @@
int main(int argc, char **argv) {
struct passwd *user;
char *cmd;
int nullfd = -1;
if (argc < 3)
return 1;

Expand All @@ -23,6 +25,11 @@ int main(int argc, char **argv) {

setenv("HOME", user->pw_dir, true);
setenv("SHELL", user->pw_shell, true);

nullfd = open("/dev/null", O_RDWR);
dup2(nullfd, STDIN_FILENO);
close(nullfd);

xasprintf(&cmd, "%s %s", USERINIT, argv[2]);
execl(user->pw_shell, user->pw_shell, "-c", cmd, NULL);
execl(user->pw_shell, "-", "-c", cmd, NULL);
}

0 comments on commit 91102b6

Please sign in to comment.