From 5703540c0ff8923681cb35ffb2c64f41d7134f04 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 2 Oct 2013 00:30:24 +0200 Subject: [PATCH] Start the initial root shell in root's home directory. --- utils/init.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/init.cpp b/utils/init.cpp index 5105da87..c0dc5847 100644 --- a/utils/init.cpp +++ b/utils/init.cpp @@ -182,11 +182,14 @@ int child() tcsetpgrp(0, getpid()); const char* default_shell = "sh"; + const char* default_home = "/root"; const char* shell; + const char* home; if ( struct passwd* passwd = getpwuid(getuid()) ) { setenv("USERNAME", passwd->pw_name, 1); - setenv("HOME", passwd->pw_dir, 1); + home = passwd->pw_dir[0] ? passwd->pw_dir : default_home; + setenv("HOME", default_home, 1); shell = passwd->pw_shell[0] ? passwd->pw_shell : default_shell; setenv("SHELL", shell, 1); setenv("DEFAULT_STUFF", "NO", 1); @@ -194,11 +197,13 @@ int child() else { setenv("USERNAME", "root", 1); - setenv("HOME", "/root", 1); + setenv("HOME", home = default_home, 1); setenv("SHELL", shell = default_shell, 1); setenv("DEFAULT_STUFF", "YES", 1); } + chdir(home); + const char* newargv[] = { shell, NULL }; execvp(shell, (char* const*) newargv);