diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-01-23 01:34:05 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-01-23 01:34:05 +0000 |
commit | de552874d2074ac48ea4b834d61c54e1b6971be3 (patch) | |
tree | 0360b39142f1c85e1cac2637e09c6e452cf1a444 /init | |
parent | f4acea8cf5175de2292c86b58f2f30d262f14345 (diff) | |
download | busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.tar.gz busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.tar.bz2 busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.zip |
Some busybox updates. You no longer _have_ to put a "-" in front of tar
options, logger is better behaved and has a "-t" option now. init now supports
the kernel chroot patch, so you can chroot to a new device and umount the old
root.
-Erik
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 91 |
1 files changed, 86 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c index 913436353..b0a85829d 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -147,7 +147,9 @@ void message(int device, char *fmt, ...) | |||
147 | va_start(arguments, fmt); | 147 | va_start(arguments, fmt); |
148 | vsnprintf(msg, sizeof(msg), fmt, arguments); | 148 | vsnprintf(msg, sizeof(msg), fmt, arguments); |
149 | va_end(arguments); | 149 | va_end(arguments); |
150 | openlog( "init", 0, LOG_DAEMON); | ||
150 | syslog(LOG_DAEMON|LOG_NOTICE, msg); | 151 | syslog(LOG_DAEMON|LOG_NOTICE, msg); |
152 | closelog(); | ||
151 | } | 153 | } |
152 | 154 | ||
153 | #else | 155 | #else |
@@ -268,7 +270,7 @@ static void console_init() | |||
268 | #if #cpu(sparc) | 270 | #if #cpu(sparc) |
269 | /* sparc kernel supports console=tty[ab] parameter which is also | 271 | /* sparc kernel supports console=tty[ab] parameter which is also |
270 | * passed to init, so catch it here */ | 272 | * passed to init, so catch it here */ |
271 | else if ((s = getenv("console")) != NULL) {*/ | 273 | else if ((s = getenv("console")) != NULL) { |
272 | /* remap tty[ab] to /dev/ttyS[01] */ | 274 | /* remap tty[ab] to /dev/ttyS[01] */ |
273 | if (strcmp( s, "ttya" )==0) | 275 | if (strcmp( s, "ttya" )==0) |
274 | snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0); | 276 | snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0); |
@@ -507,7 +509,83 @@ static void reboot_signal(int sig) | |||
507 | exit(0); | 509 | exit(0); |
508 | } | 510 | } |
509 | 511 | ||
510 | #endif | 512 | #if defined BB_FEATURE_INIT_CHROOT |
513 | static void check_chroot(int sig) | ||
514 | { | ||
515 | char *argv_init[2] = { "init", NULL, }; | ||
516 | char *envp_init[3] = { "HOME=/", "TERM=linux", NULL, }; | ||
517 | char rootpath[256], *tc; | ||
518 | int fd; | ||
519 | |||
520 | if ((fd = open("/proc/sys/kernel/init-chroot", O_RDONLY)) == -1) { | ||
521 | message(CONSOLE, "SIGHUP recived, but could not open proc file\r\n"); | ||
522 | sleep(2); | ||
523 | return; | ||
524 | } | ||
525 | if (read(fd, rootpath, sizeof(rootpath)) == -1) { | ||
526 | message(CONSOLE, "SIGHUP recived, but could not read proc file\r\n"); | ||
527 | sleep(2); | ||
528 | return; | ||
529 | } | ||
530 | close(fd); | ||
531 | |||
532 | if (rootpath[0] == '\0') { | ||
533 | message(CONSOLE, "SIGHUP recived, but new root is not valid: %s\r\n", | ||
534 | rootpath); | ||
535 | sleep(2); | ||
536 | return; | ||
537 | } | ||
538 | |||
539 | tc = strrchr(rootpath, '\n'); | ||
540 | *tc = '\0'; | ||
541 | |||
542 | /* Ok, making it this far means we commit */ | ||
543 | message(CONSOLE, "Please stand by, changing root to `%s'.\r\n", rootpath); | ||
544 | |||
545 | /* kill all other programs first */ | ||
546 | message(CONSOLE, "Sending SIGTERM to all processes.\r\n"); | ||
547 | kill(-1, SIGTERM); | ||
548 | sleep(2); | ||
549 | sync(); | ||
550 | |||
551 | message(CONSOLE, "Sending SIGKILL to all processes.\r\n"); | ||
552 | kill(-1, SIGKILL); | ||
553 | sleep(2); | ||
554 | sync(); | ||
555 | |||
556 | /* ok, we don't need /proc anymore. we also assume that the signaling | ||
557 | * process left the rest of the filesystems alone for us */ | ||
558 | umount("/proc"); | ||
559 | |||
560 | /* Ok, now we chroot. Hopefully we only have two things mounted, the | ||
561 | * new chroot'd mount point, and the old "/" mount. s, | ||
562 | * we go ahead and unmount the old "/". This should trigger the kernel | ||
563 | * to set things up the Right Way(tm). */ | ||
564 | |||
565 | if (!chroot(rootpath)) | ||
566 | umount("/dev/root"); | ||
567 | |||
568 | /* If the chroot fails, we are already too far to turn back, so we | ||
569 | * continue and hope that executing init below will revive the system */ | ||
570 | |||
571 | /* close all of our descriptors and open new ones */ | ||
572 | close(0); | ||
573 | close(1); | ||
574 | close(2); | ||
575 | open("/dev/console", O_RDWR, 0); | ||
576 | dup(0); | ||
577 | dup(0); | ||
578 | |||
579 | message(CONSOLE, "Executing real init...\r\n"); | ||
580 | /* execute init in the (hopefully) new root */ | ||
581 | execve("/sbin/init",argv_init,envp_init); | ||
582 | |||
583 | message(CONSOLE, "ERROR: Could not exec new init. Hit ctrl+alt+delete to reboot.\r\n"); | ||
584 | return; | ||
585 | } | ||
586 | #endif /* BB_FEATURE_INIT_CHROOT */ | ||
587 | |||
588 | #endif /* ! DEBUG_INIT */ | ||
511 | 589 | ||
512 | void new_initAction (initActionEnum action, | 590 | void new_initAction (initActionEnum action, |
513 | char* process, char* cons) | 591 | char* process, char* cons) |
@@ -516,10 +594,10 @@ void new_initAction (initActionEnum action, | |||
516 | 594 | ||
517 | /* If BusyBox detects that a serial console is in use, | 595 | /* If BusyBox detects that a serial console is in use, |
518 | * then entries containing non-empty id fields will _not_ be run. | 596 | * then entries containing non-empty id fields will _not_ be run. |
597 | * The exception to this rule is the null device. | ||
519 | */ | 598 | */ |
520 | if (secondConsole == NULL && *cons != '\0') { | 599 | if (secondConsole == NULL && (*cons != '\0' || strncmp(cons, "null", 4))) |
521 | return; | 600 | return; |
522 | } | ||
523 | 601 | ||
524 | newAction = calloc ((size_t)(1), sizeof(initAction)); | 602 | newAction = calloc ((size_t)(1), sizeof(initAction)); |
525 | if (!newAction) { | 603 | if (!newAction) { |
@@ -662,7 +740,7 @@ extern int init_main(int argc, char **argv) | |||
662 | int status; | 740 | int status; |
663 | 741 | ||
664 | #ifndef DEBUG_INIT | 742 | #ifndef DEBUG_INIT |
665 | /* Expect to be PID 1 iff we are run as init (not linuxrc) */ | 743 | /* Expect to be PID 1 if we are run as init (not linuxrc) */ |
666 | if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) { | 744 | if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) { |
667 | usage( "init\n\nInit is the parent of all processes.\n\n" | 745 | usage( "init\n\nInit is the parent of all processes.\n\n" |
668 | "This version of init is designed to be run only by the kernel\n"); | 746 | "This version of init is designed to be run only by the kernel\n"); |
@@ -676,6 +754,9 @@ extern int init_main(int argc, char **argv) | |||
676 | signal(SIGUSR2, reboot_signal); | 754 | signal(SIGUSR2, reboot_signal); |
677 | signal(SIGINT, reboot_signal); | 755 | signal(SIGINT, reboot_signal); |
678 | signal(SIGTERM, reboot_signal); | 756 | signal(SIGTERM, reboot_signal); |
757 | #if defined BB_FEATURE_INIT_CHROOT | ||
758 | signal(SIGHUP, check_chroot); | ||
759 | #endif | ||
679 | 760 | ||
680 | /* Turn off rebooting via CTL-ALT-DEL -- we get a | 761 | /* Turn off rebooting via CTL-ALT-DEL -- we get a |
681 | * SIGINT on CAD so we can shut things down gracefully... */ | 762 | * SIGINT on CAD so we can shut things down gracefully... */ |