aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-05-30 12:10:29 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-05-30 12:10:29 +0000
commit3ab3080bc2c52216b5f4fb2ffbef74ec5e6c1d86 (patch)
treee4b2fc212c2e9e96465cbed20400abd439ba84a1
parent752f0a6001b7b023cd6c21b906eb5c0ef7bcbd66 (diff)
downloadbusybox-3ab3080bc2c52216b5f4fb2ffbef74ec5e6c1d86.tar.gz
- 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
-rw-r--r--init/init.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/init/init.c b/init/init.c
index 10cb015dd..9cbe8189a 100644
--- a/init/init.c
+++ b/init/init.c
@@ -174,7 +174,7 @@ static const char * const environment[] = {
/* Function prototypes */
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);
@@ -200,14 +200,14 @@ static void message(int device, const char *fmt, ...)
{
va_list arguments;
int l;
- char msg[1024];
+ RESERVE_CONFIG_BUFFER(msg, 1024);
#ifndef CONFIG_SYSLOGD
static int log_fd = -1;
#endif
msg[0] = '\r';
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);
#ifdef CONFIG_SYSLOGD
@@ -258,6 +258,7 @@ static void message(int device, const char *fmt, ...)
#endif
}
}
+ RELEASE_CONFIG_BUFFER(msg);
}
/* 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)
{
- int i, junk;
+ int i;
pid_t pid;
char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
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
* supplied terminal to be the controlling tty. */
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
- pid_t pgrp, tmp_pid;
/* Now fork off another process to just hang around */
if ((pid = fork()) < 0) {
@@ -468,17 +468,9 @@ static pid_t run(const struct init_action *a)
signal(SIGQUIT, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
- /* Wait for child to exit */
- while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
- if (tmp_pid == -1 && errno == ECHILD) {
- break;
- }
- /* FIXME handle other errors */
- }
-
+ waitfor(NULL, pid);
/* See if stealing the controlling tty back is necessary */
- pgrp = tcgetpgrp(0);
- if (pgrp != getpid())
+ if (tcgetpgrp(0) != getpid())
_exit(0);
/* 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);
_exit(0);
}
- while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
- if (tmp_pid < 0 && errno == ECHILD)
- break;
- }
+ waitfor(NULL, pid);
_exit(0);
}
@@ -603,15 +592,15 @@ static pid_t run(const struct init_action *a)
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;
- pid = run(a);
+ runpid = (NULL == a)? pid : run(a);
while (1) {
- wpid = waitpid(pid,&status,0);
- if (wpid == pid)
+ wpid = waitpid(runpid,&status,0);
+ if (wpid == runpid)
break;
if (wpid == -1 && errno == ECHILD) {
/* we missed its termination */
@@ -634,7 +623,7 @@ static void run_actions(int action)
if (access(a->terminal, R_OK | W_OK)) {
delete_init_action(a);
} else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
- waitfor(a);
+ waitfor(a, 0);
delete_init_action(a);
} else if (a->action & ONCE) {
run(a);