From 91102b6b5c43f11a91a4b8b14f47bf65f2c94582 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Mon, 22 Jul 2024 20:40:08 +0200 Subject: [PATCH] user-init.c: redirect stdin to /dev/null and start a login shell Signed-off-by: Anna (navi) Figueiredo Gomes --- src/user_init/user_init.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/user_init/user_init.c b/src/user_init/user_init.c index a9072e3ab..2f3c47580 100644 --- a/src/user_init/user_init.c +++ b/src/user_init/user_init.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "helpers.h" #include "rc.h" @@ -12,6 +13,7 @@ int main(int argc, char **argv) { struct passwd *user; char *cmd; + int nullfd = -1; if (argc < 3) return 1; @@ -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); }