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

Set the root user's home directory, username and shell in init.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-10-01 23:13:01 +02:00
parent 6a9eee3238
commit 5582cb4065

View file

@ -33,6 +33,8 @@
#include <errno.h> #include <errno.h>
#include <error.h> #include <error.h>
#include <fcntl.h> #include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -179,11 +181,28 @@ int child()
setpgid(0, 0); setpgid(0, 0);
tcsetpgrp(0, getpid()); tcsetpgrp(0, getpid());
const char* programname = "sh"; const char* default_shell = "sh";
const char* newargv[] = { programname, NULL }; const char* shell;
if ( struct passwd* passwd = getpwuid(getuid()) )
{
setenv("USERNAME", passwd->pw_name, 1);
setenv("HOME", passwd->pw_dir, 1);
shell = passwd->pw_shell[0] ? passwd->pw_shell : default_shell;
setenv("SHELL", shell, 1);
setenv("DEFAULT_STUFF", "NO", 1);
}
else
{
setenv("USERNAME", "root", 1);
setenv("HOME", "/root", 1);
setenv("SHELL", shell = default_shell, 1);
setenv("DEFAULT_STUFF", "YES", 1);
}
execvp(programname, (char* const*) newargv); const char* newargv[] = { shell, NULL };
error(0, errno, "%s", programname);
execvp(shell, (char* const*) newargv);
error(0, errno, "%s", shell);
return 2; return 2;
} }