Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/init/init.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/init/init.c
r2725 r3232 10 10 */ 11 11 12 //applet:IF_INIT(APPLET(init, _BB_DIR_SBIN, _BB_SUID_DROP))13 //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, _BB_DIR_ROOT, _BB_SUID_DROP, linuxrc))12 //applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) 13 //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) 14 14 15 15 //kbuild:lib-$(CONFIG_INIT) += init.o … … 109 109 //config: sets TERM to "vt102" if one is found. 110 110 111 #define DEBUG_SEGV_HANDLER 0 112 111 113 #include "libbb.h" 112 114 #include <syslog.h> … … 114 116 #include <sys/resource.h> 115 117 #ifdef __linux__ 116 #include <linux/vt.h> 117 #endif 118 #if ENABLE_FEATURE_UTMP 119 # include <utmp.h> /* DEAD_PROCESS */ 118 # include <linux/vt.h> 119 # include <sys/sysinfo.h> 120 120 #endif 121 121 #include "reboot.h" /* reboot() constants */ 122 123 #if DEBUG_SEGV_HANDLER 124 # undef _GNU_SOURCE 125 # define _GNU_SOURCE 1 126 # undef __USE_GNU 127 # define __USE_GNU 1 128 # include <execinfo.h> 129 # include <sys/ucontext.h> 130 #endif 122 131 123 132 /* Used only for sanitizing purposes in set_sane_term() below. On systems where … … 402 411 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */); 403 412 413 command += dash; 414 404 415 /* See if any special /bin/sh requiring characters are present */ 405 416 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { 406 strcpy(buf, "exec "); 407 strcpy(buf + 5, command + dash); /* excluding "-" */ 417 sprintf(buf, "exec %s", command); /* excluding "-" */ 408 418 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */ 409 419 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash); … … 411 421 cmd[2] = buf; 412 422 cmd[3] = NULL; 423 command = LIBBB_DEFAULT_LOGIN_SHELL + 1; 413 424 } else { 414 425 /* Convert command (char*) into cmd (char**, one word per string) */ 415 426 char *word, *next; 416 427 int i = 0; 417 next = strcpy(buf, command); /* including "-" */ 428 next = strcpy(buf, command - dash); /* command including "-" */ 429 command = next + dash; 418 430 while ((word = strsep(&next, " \t")) != NULL) { 419 431 if (*word != '\0') { /* not two spaces/tabs together? */ … … 426 438 /* If we saw leading "-", it is interactive shell. 427 439 * Try harder to give it a controlling tty. 428 * And skip "-" in actual exec call. */429 if ( dash) {440 */ 441 if (ENABLE_FEATURE_INIT_SCTTY && dash) { 430 442 /* _Attempt_ to make stdin a controlling tty. */ 431 i f (ENABLE_FEATURE_INIT_SCTTY)432 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);433 }434 BB_EXECVP(c md[0] + dash, cmd);435 message(L_LOG | L_CONSOLE, "can't run '%s': %s", c md[0], strerror(errno));443 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/); 444 } 445 /* Here command never contains the dash, cmd[0] might */ 446 BB_EXECVP(command, cmd); 447 message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno)); 436 448 /* returns if execvp fails */ 437 449 } … … 509 521 /* Log the process name and args */ 510 522 message(L_LOG, "starting pid %d, tty '%s': '%s'", 511 523 getpid(), a->terminal, a->command); 512 524 513 525 /* Now run it. The new program will take over this PID, … … 523 535 524 536 if (pid > 0) { 537 update_utmp(pid, DEAD_PROCESS, 538 /*tty_name:*/ NULL, 539 /*username:*/ NULL, 540 /*hostname:*/ NULL 541 ); 525 542 for (a = init_action_list; a; a = a->next) { 526 543 if (a->pid == pid) { … … 529 546 } 530 547 } 531 update_utmp(pid, DEAD_PROCESS, /*tty_name:*/ NULL,532 /*username:*/ NULL,533 /*hostname:*/ NULL);534 548 } 535 549 return NULL; … … 596 610 nextp = &init_action_list; 597 611 while ((a = *nextp) != NULL) { 598 /* Don't enter action if it's already in the list ,612 /* Don't enter action if it's already in the list. 599 613 * This prevents losing running RESPAWNs. 600 614 */ … … 608 622 nextp = &(*nextp)->next; 609 623 a->next = NULL; 610 break;624 goto append; 611 625 } 612 626 nextp = &a->next; 613 627 } 614 628 615 if (!a)616 a = xzalloc(sizeof(*a)); 629 a = xzalloc(sizeof(*a)); 630 617 631 /* Append to the end of the list */ 632 append: 618 633 *nextp = a; 619 634 a->action_type = action_type; … … 954 969 } 955 970 971 #if DEBUG_SEGV_HANDLER 972 static 973 void handle_sigsegv(int sig, siginfo_t *info, void *ucontext) 974 { 975 long ip; 976 ucontext_t *uc; 977 978 uc = ucontext; 979 ip = uc->uc_mcontext.gregs[REG_EIP]; 980 fdprintf(2, "signal:%d address:0x%lx ip:0x%lx\n", 981 sig, 982 /* this is void*, but using %p would print "(null)" 983 * even for ptrs which are not exactly 0, but, say, 0x123: 984 */ 985 (long)info->si_addr, 986 ip); 987 { 988 /* glibc extension */ 989 void *array[50]; 990 int size; 991 size = backtrace(array, 50); 992 backtrace_symbols_fd(array, size, 2); 993 } 994 for (;;) sleep(9999); 995 } 996 #endif 997 956 998 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 957 999 int init_main(int argc UNUSED_PARAM, char **argv) … … 960 1002 return kill(1, SIGHUP); 961 1003 } 1004 1005 #if DEBUG_SEGV_HANDLER 1006 { 1007 struct sigaction sa; 1008 memset(&sa, 0, sizeof(sa)); 1009 sa.sa_sigaction = handle_sigsegv; 1010 sa.sa_flags = SA_SIGINFO; 1011 sigaction(SIGSEGV, &sa, NULL); 1012 sigaction(SIGILL, &sa, NULL); 1013 sigaction(SIGFPE, &sa, NULL); 1014 sigaction(SIGBUS, &sa, NULL); 1015 } 1016 #endif 962 1017 963 1018 if (!DEBUG_INIT) {
Note:
See TracChangeset
for help on using the changeset viewer.