Two patches from Magick <magick@linux-fan.com>:

1st makes init smaller, and fixes a bug with AskFirst. Reading from
    /dev/null gives EOF.
    2nd makes init run the command's in the order of inittab, as in
    FIFO instead of LIFO.
This commit is contained in:
Eric Andersen 2001-09-05 20:18:15 +00:00
parent b9408504f5
commit 1644db9a2b
3 changed files with 51 additions and 38 deletions

View File

@ -19,6 +19,9 @@
-- Fix sed s/[/]// handling (closes: #1208). -- Fix sed s/[/]// handling (closes: #1208).
-- Fix `-/bin/sh' invocation (closes: #1209). -- Fix `-/bin/sh' invocation (closes: #1209).
-- Fix ash exec (noted by Arne Bernin). -- Fix ash exec (noted by Arne Bernin).
* Magick
-- maked init run inittab command's in inittab order (
(i.e. FIFO instead of LIFO).
-Erik Andersen, --not yet released-- -Erik Andersen, --not yet released--

43
init.c
View File

@ -203,9 +203,7 @@ static void message(int device, char *fmt, ...)
va_start(arguments, fmt); va_start(arguments, fmt);
vsnprintf(msg, sizeof(msg), fmt, arguments); vsnprintf(msg, sizeof(msg), fmt, arguments);
va_end(arguments); va_end(arguments);
openlog(applet_name, 0, LOG_USER); syslog_msg(LOG_USER, LOG_USER|LOG_INFO, msg);
syslog(LOG_USER|LOG_INFO, msg);
closelog();
} }
#else #else
static int log_fd = -1; static int log_fd = -1;
@ -703,6 +701,9 @@ static void ctrlaltdel_signal(int sig)
static void new_initAction(initActionEnum action, char *process, char *cons) static void new_initAction(initActionEnum action, char *process, char *cons)
{ {
initAction *newAction; initAction *newAction;
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
initAction *a;
#endif
if (*cons == '\0') if (*cons == '\0')
cons = console; cons = console;
@ -714,14 +715,25 @@ static void new_initAction(initActionEnum action, char *process, char *cons)
if (secondConsole == NULL && strcmp(cons, console) if (secondConsole == NULL && strcmp(cons, console)
&& strcmp(cons, "/dev/null")) && strcmp(cons, "/dev/null"))
return; return;
if (strcmp(cons, "/dev/null") == 0 && action == ASKFIRST)
return;
newAction = calloc((size_t) (1), sizeof(initAction)); newAction = calloc((size_t) (1), sizeof(initAction));
if (!newAction) { if (!newAction) {
message(LOG | CONSOLE, "Memory allocation failure\n"); message(LOG | CONSOLE, "Memory allocation failure\n");
loop_forever(); loop_forever();
} }
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
for (a = initActionList; a && a->nextPtr; a = a->nextPtr) ;
if (a) {
a->nextPtr = newAction;
} else {
initActionList = newAction;
}
#else
newAction->nextPtr = initActionList; newAction->nextPtr = initActionList;
initActionList = newAction; initActionList = newAction;
#endif
strncpy(newAction->process, process, 255); strncpy(newAction->process, process, 255);
newAction->action = action; newAction->action = action;
strncpy(newAction->console, cons, 255); strncpy(newAction->console, cons, 255);
@ -770,10 +782,17 @@ static void parse_inittab(void)
#endif #endif
/* Reboot on Ctrl-Alt-Del */ /* Reboot on Ctrl-Alt-Del */
new_initAction(CTRLALTDEL, "/sbin/reboot", console); new_initAction(CTRLALTDEL, "/sbin/reboot", console);
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
/* Umount all filesystems on halt/reboot */
new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Swapoff on halt/reboot */
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
#else
/* Swapoff on halt/reboot */ /* Swapoff on halt/reboot */
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console); new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */ /* Umount all filesystems on halt/reboot */
new_initAction(SHUTDOWN, "/bin/umount -a -r", console); new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
#endif
/* Askfirst shell on tty1 */ /* Askfirst shell on tty1 */
new_initAction(ASKFIRST, LOGIN_SHELL, console); new_initAction(ASKFIRST, LOGIN_SHELL, console);
/* Askfirst shell on tty2 */ /* Askfirst shell on tty2 */
@ -960,23 +979,9 @@ extern int init_main(int argc, char **argv)
/* Now run everything that needs to be run */ /* Now run everything that needs to be run */
/* First run the sysinit command */ /* First run the sysinit command */
for (a = initActionList; a; a = tmp) { run_actions(SYSINIT);
tmp = a->nextPtr;
if (a->action == SYSINIT) {
waitfor(a->process, a->console, FALSE);
/* Now remove the "sysinit" entry from the list */
delete_initAction(a);
}
}
/* Next run anything that wants to block */ /* Next run anything that wants to block */
for (a = initActionList; a; a = tmp) { run_actions(WAIT);
tmp = a->nextPtr;
if (a->action == WAIT) {
waitfor(a->process, a->console, FALSE);
/* Now remove the "wait" entry from the list */
delete_initAction(a);
}
}
/* Next run anything to be run only once */ /* Next run anything to be run only once */
for (a = initActionList; a; a = tmp) { for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr; tmp = a->nextPtr;

View File

@ -203,9 +203,7 @@ static void message(int device, char *fmt, ...)
va_start(arguments, fmt); va_start(arguments, fmt);
vsnprintf(msg, sizeof(msg), fmt, arguments); vsnprintf(msg, sizeof(msg), fmt, arguments);
va_end(arguments); va_end(arguments);
openlog(applet_name, 0, LOG_USER); syslog_msg(LOG_USER, LOG_USER|LOG_INFO, msg);
syslog(LOG_USER|LOG_INFO, msg);
closelog();
} }
#else #else
static int log_fd = -1; static int log_fd = -1;
@ -703,6 +701,9 @@ static void ctrlaltdel_signal(int sig)
static void new_initAction(initActionEnum action, char *process, char *cons) static void new_initAction(initActionEnum action, char *process, char *cons)
{ {
initAction *newAction; initAction *newAction;
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
initAction *a;
#endif
if (*cons == '\0') if (*cons == '\0')
cons = console; cons = console;
@ -714,14 +715,25 @@ static void new_initAction(initActionEnum action, char *process, char *cons)
if (secondConsole == NULL && strcmp(cons, console) if (secondConsole == NULL && strcmp(cons, console)
&& strcmp(cons, "/dev/null")) && strcmp(cons, "/dev/null"))
return; return;
if (strcmp(cons, "/dev/null") == 0 && action == ASKFIRST)
return;
newAction = calloc((size_t) (1), sizeof(initAction)); newAction = calloc((size_t) (1), sizeof(initAction));
if (!newAction) { if (!newAction) {
message(LOG | CONSOLE, "Memory allocation failure\n"); message(LOG | CONSOLE, "Memory allocation failure\n");
loop_forever(); loop_forever();
} }
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
for (a = initActionList; a && a->nextPtr; a = a->nextPtr) ;
if (a) {
a->nextPtr = newAction;
} else {
initActionList = newAction;
}
#else
newAction->nextPtr = initActionList; newAction->nextPtr = initActionList;
initActionList = newAction; initActionList = newAction;
#endif
strncpy(newAction->process, process, 255); strncpy(newAction->process, process, 255);
newAction->action = action; newAction->action = action;
strncpy(newAction->console, cons, 255); strncpy(newAction->console, cons, 255);
@ -770,10 +782,17 @@ static void parse_inittab(void)
#endif #endif
/* Reboot on Ctrl-Alt-Del */ /* Reboot on Ctrl-Alt-Del */
new_initAction(CTRLALTDEL, "/sbin/reboot", console); new_initAction(CTRLALTDEL, "/sbin/reboot", console);
#ifdef BB_FEATURE_INIT_NORMAL_ORDER
/* Umount all filesystems on halt/reboot */
new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Swapoff on halt/reboot */
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
#else
/* Swapoff on halt/reboot */ /* Swapoff on halt/reboot */
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console); new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */ /* Umount all filesystems on halt/reboot */
new_initAction(SHUTDOWN, "/bin/umount -a -r", console); new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
#endif
/* Askfirst shell on tty1 */ /* Askfirst shell on tty1 */
new_initAction(ASKFIRST, LOGIN_SHELL, console); new_initAction(ASKFIRST, LOGIN_SHELL, console);
/* Askfirst shell on tty2 */ /* Askfirst shell on tty2 */
@ -960,23 +979,9 @@ extern int init_main(int argc, char **argv)
/* Now run everything that needs to be run */ /* Now run everything that needs to be run */
/* First run the sysinit command */ /* First run the sysinit command */
for (a = initActionList; a; a = tmp) { run_actions(SYSINIT);
tmp = a->nextPtr;
if (a->action == SYSINIT) {
waitfor(a->process, a->console, FALSE);
/* Now remove the "sysinit" entry from the list */
delete_initAction(a);
}
}
/* Next run anything that wants to block */ /* Next run anything that wants to block */
for (a = initActionList; a; a = tmp) { run_actions(WAIT);
tmp = a->nextPtr;
if (a->action == WAIT) {
waitfor(a->process, a->console, FALSE);
/* Now remove the "wait" entry from the list */
delete_initAction(a);
}
}
/* Next run anything to be run only once */ /* Next run anything to be run only once */
for (a = initActionList; a; a = tmp) { for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr; tmp = a->nextPtr;