1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Start the initial root shell in root's home directory.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-10-02 00:30:24 +02:00
parent b3b2e99b9c
commit 5703540c0f

View file

@ -182,11 +182,14 @@ int child()
tcsetpgrp(0, getpid()); tcsetpgrp(0, getpid());
const char* default_shell = "sh"; const char* default_shell = "sh";
const char* default_home = "/root";
const char* shell; const char* shell;
const char* home;
if ( struct passwd* passwd = getpwuid(getuid()) ) if ( struct passwd* passwd = getpwuid(getuid()) )
{ {
setenv("USERNAME", passwd->pw_name, 1); 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; shell = passwd->pw_shell[0] ? passwd->pw_shell : default_shell;
setenv("SHELL", shell, 1); setenv("SHELL", shell, 1);
setenv("DEFAULT_STUFF", "NO", 1); setenv("DEFAULT_STUFF", "NO", 1);
@ -194,11 +197,13 @@ int child()
else else
{ {
setenv("USERNAME", "root", 1); setenv("USERNAME", "root", 1);
setenv("HOME", "/root", 1); setenv("HOME", home = default_home, 1);
setenv("SHELL", shell = default_shell, 1); setenv("SHELL", shell = default_shell, 1);
setenv("DEFAULT_STUFF", "YES", 1); setenv("DEFAULT_STUFF", "YES", 1);
} }
chdir(home);
const char* newargv[] = { shell, NULL }; const char* newargv[] = { shell, NULL };
execvp(shell, (char* const*) newargv); execvp(shell, (char* const*) newargv);