Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/init/init.c
Show First 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | |||||
* - single_user if fork/execv/waitpid failed, or if the script | * - single_user if fork/execv/waitpid failed, or if the script | ||||
* terminated with a signal or exit code != 0. | * terminated with a signal or exit code != 0. | ||||
* - death_single if a SIGTERM was delivered to init(8). | * - death_single if a SIGTERM was delivered to init(8). | ||||
*/ | */ | ||||
static state_func_t | static state_func_t | ||||
run_script(const char *script) | run_script(const char *script) | ||||
{ | { | ||||
pid_t pid, wpid; | pid_t pid, wpid; | ||||
int status; | int error, status; | ||||
char *argv[4]; | char *argv[4]; | ||||
const char *shell; | const char *shell; | ||||
struct sigaction sa; | struct sigaction sa; | ||||
shell = get_shell(); | shell = get_shell(); | ||||
if ((pid = fork()) == 0) { | if ((pid = fork()) == 0) { | ||||
sigemptyset(&sa.sa_mask); | sigemptyset(&sa.sa_mask); | ||||
Show All 12 Lines | if ((pid = fork()) == 0) { | ||||
argv[2] = runcom_mode == AUTOBOOT ? _autoboot : 0; | argv[2] = runcom_mode == AUTOBOOT ? _autoboot : 0; | ||||
argv[3] = 0; | argv[3] = 0; | ||||
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); | sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); | ||||
#ifdef LOGIN_CAP | #ifdef LOGIN_CAP | ||||
setprocresources(RESOURCE_RC); | setprocresources(RESOURCE_RC); | ||||
#endif | #endif | ||||
/* | |||||
* Try to directly execute the script first. If it | |||||
* fails, try the old method of passing the script path | |||||
* to sh(1). Don't complain if it fails because of | |||||
* the missing execute bit. | |||||
*/ | |||||
error = access(script, X_OK); | |||||
if (error == 0) { | |||||
execv(script, argv + 1); | |||||
warning("can't exec %s: %m", script); | |||||
} else if (errno != EACCES) { | |||||
warning("can't access %s: %m", script); | |||||
} | |||||
execv(shell, argv); | execv(shell, argv); | ||||
stall("can't exec %s for %s: %m", shell, script); | stall("can't exec %s for %s: %m", shell, script); | ||||
_exit(1); /* force single user mode */ | _exit(1); /* force single user mode */ | ||||
} | } | ||||
if (pid == -1) { | if (pid == -1) { | ||||
emergency("can't fork for %s on %s: %m", shell, script); | emergency("can't fork for %s on %s: %m", shell, script); | ||||
while (waitpid(-1, (int *) 0, WNOHANG) > 0) | while (waitpid(-1, (int *) 0, WNOHANG) > 0) | ||||
▲ Show 20 Lines • Show All 752 Lines • ▼ Show 20 Lines | |||||
* -1 fatal error - can't run script | * -1 fatal error - can't run script | ||||
* 0 good. | * 0 good. | ||||
* >0 some error (exit code) | * >0 some error (exit code) | ||||
*/ | */ | ||||
static int | static int | ||||
runshutdown(void) | runshutdown(void) | ||||
{ | { | ||||
pid_t pid, wpid; | pid_t pid, wpid; | ||||
int status; | int error, status; | ||||
int shutdowntimeout; | int shutdowntimeout; | ||||
size_t len; | size_t len; | ||||
char *argv[4]; | char *argv[4]; | ||||
const char *shell; | const char *shell; | ||||
struct sigaction sa; | struct sigaction sa; | ||||
struct stat sb; | struct stat sb; | ||||
/* | /* | ||||
Show All 26 Lines | if ((pid = fork()) == 0) { | ||||
argv[2] = Reboot ? _reboot : _single; | argv[2] = Reboot ? _reboot : _single; | ||||
argv[3] = 0; | argv[3] = 0; | ||||
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); | sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0); | ||||
#ifdef LOGIN_CAP | #ifdef LOGIN_CAP | ||||
setprocresources(RESOURCE_RC); | setprocresources(RESOURCE_RC); | ||||
#endif | #endif | ||||
/* | |||||
* Try to directly execute the script first. If it | |||||
* fails, try the old method of passing the script path | |||||
* to sh(1). Don't complain if it fails because of | |||||
* the missing execute bit. | |||||
*/ | |||||
error = access(_path_rundown, X_OK); | |||||
if (error == 0) { | |||||
execv(_path_rundown, argv + 1); | |||||
warning("can't exec %s: %m", _path_rundown); | |||||
} else if (errno != EACCES) { | |||||
warning("can't access %s: %m", _path_rundown); | |||||
} | |||||
execv(shell, argv); | execv(shell, argv); | ||||
warning("can't exec %s for %s: %m", shell, _PATH_RUNDOWN); | warning("can't exec %s for %s: %m", shell, _PATH_RUNDOWN); | ||||
_exit(1); /* force single user mode */ | _exit(1); /* force single user mode */ | ||||
} | } | ||||
if (pid == -1) { | if (pid == -1) { | ||||
emergency("can't fork for %s on %s: %m", shell, _PATH_RUNDOWN); | emergency("can't fork for %s on %s: %m", shell, _PATH_RUNDOWN); | ||||
while (waitpid(-1, (int *) 0, WNOHANG) > 0) | while (waitpid(-1, (int *) 0, WNOHANG) > 0) | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |