diff options
-rw-r--r-- | busybox.def.h | 43 | ||||
-rw-r--r-- | init.c | 57 | ||||
-rw-r--r-- | init/init.c | 57 |
3 files changed, 116 insertions, 41 deletions
diff --git a/busybox.def.h b/busybox.def.h index 0e62ca781..032146519 100644 --- a/busybox.def.h +++ b/busybox.def.h @@ -1,8 +1,11 @@ -/* - * This file is parsed by sed. You MUST use single line comments. - * IE //#define BB_BLAH - */ - +// This file defines the feature set to be compiled into busybox. +// When you turn things off here, they won't be compiled in at all. +// +//// This file is parsed by sed. You MUST use single line comments. +// i.e. //#define BB_BLAH +// +// +// BusyBox Applications #define BB_BUSYBOX #define BB_CAT #define BB_CHMOD_CHOWN_CHGRP @@ -28,6 +31,7 @@ #define BB_HEAD #define BB_HOSTNAME #define BB_INIT +// Don't turn BB_INSMOD on. It doesn't work. //#define BB_INSMOD #define BB_KILL #define BB_KLOGD @@ -80,9 +84,7 @@ #define BB_UNAME #define BB_GZIP #define BB_GUNZIP -// Don't turn BB_UTILITY off. It contains support code -// that compiles to 0 if everything else if turned off. -#define BB_UTILITY +// End of Applications List // // // @@ -91,19 +93,30 @@ // pretty/useful). // // -// enable features that use the /proc filesystem +// enable features that use the /proc filesystem (apps that +// break without this will tell you on compile)... #define BB_FEATURE_USE_PROCFS -//Enable init being called as /linuxrc -#define BB_FEATURE_LINUXRC // Use termios to manipulate the screen ('more' is prettier with this on) #define BB_FEATURE_USE_TERMIOS -// calculate terminal & column widths +// calculate terminal & column widths (for more and ls) #define BB_FEATURE_AUTOWIDTH -// show username/groupnames (bypasses libc6 NSS) +// show username/groupnames (bypasses libc6 NSS) for ls #define BB_FEATURE_LS_USERNAME -// show file timestamps +// show file timestamps in ls #define BB_FEATURE_LS_TIMESTAMPS // enable ls -p and -F #define BB_FEATURE_LS_FILETYPES -// simplified ping +// Change ping implementation -- simplified, featureless, but really small. //#define BB_SIMPLE_PING +// Make init use a simplified /etc/inittab file (recommended). +#define BB_FEATURE_USE_INITTAB +//Enable init being called as /linuxrc +#define BB_FEATURE_LINUXRC +// +// +// +// Don't turn BB_UTILITY off. It contains support code +// that compiles to 0 if everything else if turned off. +#define BB_UTILITY +// +// @@ -97,7 +97,7 @@ typedef struct initActionTag initAction; struct initActionTag { pid_t pid; char process[256]; - char *console; + char console[256]; initAction *nextPtr; initActionEnum action; }; @@ -496,9 +496,16 @@ static void reboot_signal(int sig) #endif void new_initAction (const struct initActionType *a, - char* process, char* console) + char* process, char* cons) { initAction* newAction; + + /* If BusyBox detects that a serial console is in use, + * then entries containing non-empty id fields will _not_ be run. + */ + if (second_console != NULL && *cons != '\0') + return; + newAction = calloc ((size_t)(1), sizeof(initAction)); if (!newAction) { fprintf(stderr, "Memory allocation failure\n"); @@ -508,7 +515,10 @@ void new_initAction (const struct initActionType *a, initActionList = newAction; strncpy( newAction->process, process, 255); newAction->action = a->action; - newAction->console = console; + if (*cons != '\0') + strncpy(newAction->console, cons, 255); + else + strncpy(newAction->console, console, 255); newAction->pid = 0; } @@ -524,11 +534,19 @@ void delete_initAction (initAction *action) } } +/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined, + * then parse_inittab() simply adds in some default + * actions(i.e runs INIT_SCRIPT and then starts a pair + * of "askfirst" shells. If BB_FEATURE_USE_INITTAB + * _is_ defined, but /etc/inittab is missing == same + * default behavior. + * */ void parse_inittab(void) { +#ifdef BB_FEATURE_USE_INITTAB FILE* file; - char buf[256]; - char *p, *q, *r; + char buf[256], buf1[256]; + char *p, *q, *r, *s; const struct initActionType *a = actions; int foundIt; @@ -536,7 +554,7 @@ void parse_inittab(void) file = fopen(INITTAB, "r"); if (file == NULL) { /* No inittab file -- set up some default behavior */ - +#endif /* Askfirst shell on tty1 */ new_initAction( &(actions[3]), SHELL, console ); /* Askfirst shell on tty2 */ @@ -546,6 +564,7 @@ void parse_inittab(void) new_initAction( &(actions[0]), INIT_SCRIPT, console ); return; +#ifdef BB_FEATURE_USE_INITTAB } while ( fgets(buf, 255, file) != NULL) { @@ -558,15 +577,22 @@ void parse_inittab(void) if (q != NULL) *q='\0'; - /* Skip past the ID field and the runlevel - * field (both are ignored) */ + /* Keep a copy around for posterity's sake (and error msgs) */ + strcpy(buf1, buf); + + /* Grab the ID field */ + s=p; p = strchr( p, ':'); + if ( p != NULL || *(p+1) != '\0' ) { + *p='\0'; + ++p; + } /* Now peal off the process field from the end * of the string */ q = strrchr( p, ':'); if ( q == NULL || *(q+1) == '\0' ) { - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); continue; } else { *q='\0'; @@ -576,7 +602,7 @@ void parse_inittab(void) /* Now peal off the action field */ r = strrchr( p, ':'); if ( r == NULL || *(r+1) == '\0') { - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); continue; } else { ++r; @@ -586,7 +612,7 @@ void parse_inittab(void) a = actions; while (a->name != 0) { if (strcmp(a->name, r) == 0) { - new_initAction( a, q, NULL); + new_initAction( a, q, s); foundIt=TRUE; } a++; @@ -595,13 +621,13 @@ void parse_inittab(void) continue; else { /* Choke on an unknown action */ - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); } } return; +#endif } - extern int init_main(int argc, char **argv) { initAction *a; @@ -675,6 +701,11 @@ extern int init_main(int argc, char **argv) new_initAction( &(actions[3]), SHELL, console); } else { /* Not in single user mode -- see what inittab says */ + + /* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined, + * then parse_inittab() simply adds in some default + * actions(i.e runs INIT_SCRIPT and then starts a pair + * of "askfirst" shells */ parse_inittab(); } diff --git a/init/init.c b/init/init.c index 116d07954..95c2322f7 100644 --- a/init/init.c +++ b/init/init.c @@ -97,7 +97,7 @@ typedef struct initActionTag initAction; struct initActionTag { pid_t pid; char process[256]; - char *console; + char console[256]; initAction *nextPtr; initActionEnum action; }; @@ -496,9 +496,16 @@ static void reboot_signal(int sig) #endif void new_initAction (const struct initActionType *a, - char* process, char* console) + char* process, char* cons) { initAction* newAction; + + /* If BusyBox detects that a serial console is in use, + * then entries containing non-empty id fields will _not_ be run. + */ + if (second_console != NULL && *cons != '\0') + return; + newAction = calloc ((size_t)(1), sizeof(initAction)); if (!newAction) { fprintf(stderr, "Memory allocation failure\n"); @@ -508,7 +515,10 @@ void new_initAction (const struct initActionType *a, initActionList = newAction; strncpy( newAction->process, process, 255); newAction->action = a->action; - newAction->console = console; + if (*cons != '\0') + strncpy(newAction->console, cons, 255); + else + strncpy(newAction->console, console, 255); newAction->pid = 0; } @@ -524,11 +534,19 @@ void delete_initAction (initAction *action) } } +/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined, + * then parse_inittab() simply adds in some default + * actions(i.e runs INIT_SCRIPT and then starts a pair + * of "askfirst" shells. If BB_FEATURE_USE_INITTAB + * _is_ defined, but /etc/inittab is missing == same + * default behavior. + * */ void parse_inittab(void) { +#ifdef BB_FEATURE_USE_INITTAB FILE* file; - char buf[256]; - char *p, *q, *r; + char buf[256], buf1[256]; + char *p, *q, *r, *s; const struct initActionType *a = actions; int foundIt; @@ -536,7 +554,7 @@ void parse_inittab(void) file = fopen(INITTAB, "r"); if (file == NULL) { /* No inittab file -- set up some default behavior */ - +#endif /* Askfirst shell on tty1 */ new_initAction( &(actions[3]), SHELL, console ); /* Askfirst shell on tty2 */ @@ -546,6 +564,7 @@ void parse_inittab(void) new_initAction( &(actions[0]), INIT_SCRIPT, console ); return; +#ifdef BB_FEATURE_USE_INITTAB } while ( fgets(buf, 255, file) != NULL) { @@ -558,15 +577,22 @@ void parse_inittab(void) if (q != NULL) *q='\0'; - /* Skip past the ID field and the runlevel - * field (both are ignored) */ + /* Keep a copy around for posterity's sake (and error msgs) */ + strcpy(buf1, buf); + + /* Grab the ID field */ + s=p; p = strchr( p, ':'); + if ( p != NULL || *(p+1) != '\0' ) { + *p='\0'; + ++p; + } /* Now peal off the process field from the end * of the string */ q = strrchr( p, ':'); if ( q == NULL || *(q+1) == '\0' ) { - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); continue; } else { *q='\0'; @@ -576,7 +602,7 @@ void parse_inittab(void) /* Now peal off the action field */ r = strrchr( p, ':'); if ( r == NULL || *(r+1) == '\0') { - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); continue; } else { ++r; @@ -586,7 +612,7 @@ void parse_inittab(void) a = actions; while (a->name != 0) { if (strcmp(a->name, r) == 0) { - new_initAction( a, q, NULL); + new_initAction( a, q, s); foundIt=TRUE; } a++; @@ -595,13 +621,13 @@ void parse_inittab(void) continue; else { /* Choke on an unknown action */ - fprintf(stderr, "Bad inittab entry: %s\n", buf); + fprintf(stderr, "Bad inittab entry: %s\n", buf1); } } return; +#endif } - extern int init_main(int argc, char **argv) { initAction *a; @@ -675,6 +701,11 @@ extern int init_main(int argc, char **argv) new_initAction( &(actions[3]), SHELL, console); } else { /* Not in single user mode -- see what inittab says */ + + /* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined, + * then parse_inittab() simply adds in some default + * actions(i.e runs INIT_SCRIPT and then starts a pair + * of "askfirst" shells */ parse_inittab(); } |