sbin/init/init.c
/*
 * Run the system startup script.
 */
Run the system startup script.
Run the system startup script .
state_func_t
runcom()
{
	pid_t pid, wpid;
	int status;
	char *argv[4];
	struct sigaction sa;
	if ((pid = fork()) == 0) {
		sigemptyset(&sa.sa_mask);
		sa.sa_flags = 0;
		sa.sa_handler = SIG_IGN;
		(void) sigaction(SIGTSTP, &sa, (struct sigaction *)0);
		(void) sigaction(SIGHUP, &sa, (struct sigaction *)0);
		setctty(_PATH_CONSOLE);
		argv[0] = "sh";
		argv[1] = _PATH_RUNCOM;
		argv[2] = runcom_mode == AUTOBOOT ? "autoboot" : 0;
		argv[3] = 0;
		sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0);
		execv(_PATH_BSHELL, argv);
		stall("can't exec %s for %s: %m", _PATH_BSHELL, _PATH_RUNCOM);
		_exit(1);	
	}
	if (pid == -1) {
		emergency("can't fork for %s on %s: %m",
			_PATH_BSHELL, _PATH_RUNCOM);
		while (waitpid(-1, (int *) 0, WNOHANG) > 0)
			continue;
		sleep(STALL_TIMEOUT);
		return (state_func_t) single_user;
	}
	do {
		if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1)
			collect_child(wpid);
		if (wpid == -1) {
			if (errno == EINTR)
				continue;
			warning("wait for %s on %s failed: %m; going to single user mode",
				_PATH_BSHELL, _PATH_RUNCOM);
			return (state_func_t) single_user;
		}
		if (wpid == pid && WIFSTOPPED(status)) {
			warning("init: %s on %s stopped, restarting\n",
				_PATH_BSHELL, _PATH_RUNCOM);
			kill(pid, SIGCONT);
			wpid = -1;
		}
	} while (wpid != pid);
	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM &&
	    requested_transition == catatonia) {
		sigset_t s;
		sigfillset(&s);
		for (;;)
			sigsuspend(&s);
	}
	if (!WIFEXITED(status)) {
		warning("%s on %s terminated abnormally, going to single user mode",
			_PATH_BSHELL, _PATH_RUNCOM);
		return (state_func_t) single_user;
	}
	if (WEXITSTATUS(status))
		return (state_func_t) single_user;
	runcom_mode = AUTOBOOT;		
	logwtmp("~", "reboot", "");
	return (state_func_t) read_ttys;
}
state_func_t runcom ( ) { pid_t pid , wpid ; int status ; char * argv [ 4 ] ; struct sigaction sa ; if ( ( pid = fork ( ) ) == 0 ) { sigemptyset ( & sa . sa_mask ) ; sa . sa_flags = 0 ; sa . sa_handler = SIG_IGN ; ( void ) sigaction ( SIGTSTP , & sa , ( struct sigaction * ) 0 ) ; ( void ) sigaction ( SIGHUP , & sa , ( struct sigaction * ) 0 ) ; setctty ( _PATH_CONSOLE ) ; argv [ 0 ] = " " ; argv [ 1 ] = _PATH_RUNCOM ; argv [ 2 ] = runcom_mode == AUTOBOOT ? " " : 0 ; argv [ 3 ] = 0 ; sigprocmask ( SIG_SETMASK , & sa . sa_mask , ( sigset_t * ) 0 ) ; execv ( _PATH_BSHELL , argv ) ; stall ( " " , _PATH_BSHELL , _PATH_RUNCOM ) ; _exit ( 1 ) ; } if ( pid == -1 ) { emergency ( " " , _PATH_BSHELL , _PATH_RUNCOM ) ; while ( waitpid ( -1 , ( int * ) 0 , WNOHANG ) > 0 ) continue ; sleep ( STALL_TIMEOUT ) ; return ( state_func_t ) single_user ; } do { if ( ( wpid = waitpid ( -1 , & status , WUNTRACED ) ) != -1 ) collect_child ( wpid ) ; if ( wpid == -1 ) { if ( errno == EINTR ) continue ; warning ( " " , _PATH_BSHELL , _PATH_RUNCOM ) ; return ( state_func_t ) single_user ; } if ( wpid == pid && WIFSTOPPED ( status ) ) { warning ( " \n " , _PATH_BSHELL , _PATH_RUNCOM ) ; kill ( pid , SIGCONT ) ; wpid = -1 ; } } while ( wpid != pid ) ; if ( WIFSIGNALED ( status ) && WTERMSIG ( status ) == SIGTERM && requested_transition == catatonia ) { sigset_t s ; sigfillset ( & s ) ; for ( ; ; ) sigsuspend ( & s ) ; } if ( ! WIFEXITED ( status ) ) { warning ( " " , _PATH_BSHELL , _PATH_RUNCOM ) ; return ( state_func_t ) single_user ; } if ( WEXITSTATUS ( status ) ) return ( state_func_t ) single_user ; runcom_mode = AUTOBOOT ; logwtmp ( " " , " " , " " ) ; return ( state_func_t ) read_ttys ; }
Run the system startup script.
Run the system startup script .
/* force single user mode */ /*
	 * Copied from single_user().  This is a bit paranoid.
	 */ /* /etc/rc executed /sbin/reboot; wait for the end quietly */ /* the default */ /* NB: should send a message to the session logger to avoid blocking. */