svn commit: trunk/busybox/init
aldot at busybox.net
aldot at busybox.net
Tue May 30 12:10:31 UTC 2006
Author: aldot
Date: 2006-05-30 05:10:29 -0700 (Tue, 30 May 2006)
New Revision: 15236
Log:
- 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
Modified:
trunk/busybox/init/init.c
Changeset:
Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c 2006-05-30 10:02:18 UTC (rev 15235)
+++ trunk/busybox/init/init.c 2006-05-30 12:10:29 UTC (rev 15236)
@@ -174,7 +174,7 @@
/* 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 @@
{
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 @@
#endif
}
}
+ RELEASE_CONFIG_BUFFER(msg);
}
/* Set terminal settings to reasonable defaults */
@@ -400,7 +401,7 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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);
More information about the busybox-cvs
mailing list