- use config_buffer for message()
- add second argument to waitfor(*action,pid); if action==NULL then use pid tor wait for. If an action was given, we wait for the action to finish just as before. In run() remove second and third occurance of the same functionality the waitfor() call now provides. Adjust the former only caller of waitfor accordingly. PS: Not using waitfor but creating a second function used a few bytes more than simply extending and reusing waitfor. text data bss dec hex filename 5426 32 8 5466 155a init/init.o.orig 5391 32 8 5431 1537 init/init.o
This commit is contained in:
parent
752f0a6001
commit
3ab3080bc2
39
init/init.c
39
init/init.c
@ -174,7 +174,7 @@ static const char * const environment[] = {
|
|||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
static void delete_init_action(struct init_action *a);
|
static void delete_init_action(struct init_action *a);
|
||||||
static int waitfor(const struct init_action *a);
|
static int waitfor(const struct init_action *a, pid_t pid);
|
||||||
static void halt_signal(int sig);
|
static void halt_signal(int sig);
|
||||||
|
|
||||||
|
|
||||||
@ -200,14 +200,14 @@ static void message(int device, const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list arguments;
|
va_list arguments;
|
||||||
int l;
|
int l;
|
||||||
char msg[1024];
|
RESERVE_CONFIG_BUFFER(msg, 1024);
|
||||||
#ifndef CONFIG_SYSLOGD
|
#ifndef CONFIG_SYSLOGD
|
||||||
static int log_fd = -1;
|
static int log_fd = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
msg[0] = '\r';
|
msg[0] = '\r';
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments) + 1;
|
l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
|
|
||||||
#ifdef CONFIG_SYSLOGD
|
#ifdef CONFIG_SYSLOGD
|
||||||
@ -258,6 +258,7 @@ static void message(int device, const char *fmt, ...)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RELEASE_CONFIG_BUFFER(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set terminal settings to reasonable defaults */
|
/* Set terminal settings to reasonable defaults */
|
||||||
@ -400,7 +401,7 @@ static void open_new_terminal(const char *device, char fail) {
|
|||||||
|
|
||||||
static pid_t run(const struct init_action *a)
|
static pid_t run(const struct init_action *a)
|
||||||
{
|
{
|
||||||
int i, junk;
|
int i;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
|
char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
|
||||||
char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
|
char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
|
||||||
@ -452,7 +453,6 @@ static pid_t run(const struct init_action *a)
|
|||||||
/* If the init Action requires us to wait, then force the
|
/* If the init Action requires us to wait, then force the
|
||||||
* supplied terminal to be the controlling tty. */
|
* supplied terminal to be the controlling tty. */
|
||||||
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
||||||
pid_t pgrp, tmp_pid;
|
|
||||||
|
|
||||||
/* Now fork off another process to just hang around */
|
/* Now fork off another process to just hang around */
|
||||||
if ((pid = fork()) < 0) {
|
if ((pid = fork()) < 0) {
|
||||||
@ -468,17 +468,9 @@ static pid_t run(const struct init_action *a)
|
|||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
|
||||||
/* Wait for child to exit */
|
waitfor(NULL, pid);
|
||||||
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
|
|
||||||
if (tmp_pid == -1 && errno == ECHILD) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* FIXME handle other errors */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See if stealing the controlling tty back is necessary */
|
/* See if stealing the controlling tty back is necessary */
|
||||||
pgrp = tcgetpgrp(0);
|
if (tcgetpgrp(0) != getpid())
|
||||||
if (pgrp != getpid())
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
|
||||||
/* Use a temporary process to steal the controlling tty. */
|
/* Use a temporary process to steal the controlling tty. */
|
||||||
@ -491,10 +483,7 @@ static pid_t run(const struct init_action *a)
|
|||||||
ioctl(0, TIOCSCTTY, 1);
|
ioctl(0, TIOCSCTTY, 1);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
|
waitfor(NULL, pid);
|
||||||
if (tmp_pid < 0 && errno == ECHILD)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,15 +592,15 @@ static pid_t run(const struct init_action *a)
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int waitfor(const struct init_action *a)
|
static int waitfor(const struct init_action *a, pid_t pid)
|
||||||
{
|
{
|
||||||
int pid;
|
int runpid;
|
||||||
int status, wpid;
|
int status, wpid;
|
||||||
|
|
||||||
pid = run(a);
|
runpid = (NULL == a)? pid : run(a);
|
||||||
while (1) {
|
while (1) {
|
||||||
wpid = waitpid(pid,&status,0);
|
wpid = waitpid(runpid,&status,0);
|
||||||
if (wpid == pid)
|
if (wpid == runpid)
|
||||||
break;
|
break;
|
||||||
if (wpid == -1 && errno == ECHILD) {
|
if (wpid == -1 && errno == ECHILD) {
|
||||||
/* we missed its termination */
|
/* we missed its termination */
|
||||||
@ -634,7 +623,7 @@ static void run_actions(int action)
|
|||||||
if (access(a->terminal, R_OK | W_OK)) {
|
if (access(a->terminal, R_OK | W_OK)) {
|
||||||
delete_init_action(a);
|
delete_init_action(a);
|
||||||
} else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
} else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
||||||
waitfor(a);
|
waitfor(a, 0);
|
||||||
delete_init_action(a);
|
delete_init_action(a);
|
||||||
} else if (a->action & ONCE) {
|
} else if (a->action & ONCE) {
|
||||||
run(a);
|
run(a);
|
||||||
|
Loading…
Reference in New Issue
Block a user