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:
parent
6a9eee3238
commit
5582cb4065
1 changed files with 23 additions and 4 deletions
|
@ -33,6 +33,8 @@
|
|||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
@ -179,11 +181,28 @@ int child()
|
|||
setpgid(0, 0);
|
||||
tcsetpgrp(0, getpid());
|
||||
|
||||
const char* programname = "sh";
|
||||
const char* newargv[] = { programname, NULL };
|
||||
const char* default_shell = "sh";
|
||||
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);
|
||||
error(0, errno, "%s", programname);
|
||||
const char* newargv[] = { shell, NULL };
|
||||
|
||||
execvp(shell, (char* const*) newargv);
|
||||
error(0, errno, "%s", shell);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue