Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/init
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- Location:
- branches/3.2/mindi-busybox/init
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/init/bootchartd.c
r2725 r3232 4 4 */ 5 5 6 //applet:IF_BOOTCHARTD(APPLET(bootchartd, _BB_DIR_SBIN, _BB_SUID_DROP))6 //applet:IF_BOOTCHARTD(APPLET(bootchartd, BB_DIR_SBIN, BB_SUID_DROP)) 7 7 8 8 //kbuild:lib-$(CONFIG_BOOTCHARTD) += bootchartd.o … … 209 209 } 210 210 211 static void do_logging(unsigned sample_period_us) 212 { 213 //# Enable process accounting if configured 214 //if [ "$PROCESS_ACCOUNTING" = "yes" ]; then 215 // [ -e kernel_pacct ] || : > kernel_pacct 216 // accton kernel_pacct 217 //fi 218 211 static void do_logging(unsigned sample_period_us, int process_accounting) 212 { 219 213 FILE *proc_stat = xfopen("proc_stat.log", "w"); 220 214 FILE *proc_diskstats = xfopen("proc_diskstats.log", "w"); … … 223 217 int look_for_login_process = (getppid() == 1); 224 218 unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */ 219 220 if (process_accounting) { 221 close(xopen("kernel_pacct", O_WRONLY | O_CREAT | O_TRUNC)); 222 acct("kernel_pacct"); 223 } 225 224 226 225 while (--count && !bb_got_signal) { … … 254 253 usleep(sample_period_us); 255 254 } 256 257 // [ -e kernel_pacct ] && accton off 258 } 259 260 static void finalize(char *tempdir, const char *prog) 255 } 256 257 static void finalize(char *tempdir, const char *prog, int process_accounting) 261 258 { 262 259 //# Stop process accounting if configured … … 265 262 266 263 FILE *header_fp = xfopen("header", "w"); 264 265 if (process_accounting) 266 acct(NULL); 267 267 268 268 if (prog) … … 308 308 309 309 /* Package log files */ 310 system( "tar -zcf /var/log/bootchart.tgz header *.log"); // + $pacct310 system(xasprintf("tar -zcf /var/log/bootlog.tgz header %s *.log", process_accounting ? "kernel_pacct" : "")); 311 311 /* Clean up (if we are not in detached tmpfs) */ 312 312 if (tempdir) { … … 316 316 //unlink("proc_netdev.log"); 317 317 unlink("proc_ps.log"); 318 if (process_accounting) 319 unlink("kernel_pacct"); 318 320 rmdir(tempdir); 319 321 } … … 328 330 //usage:#define bootchartd_full_usage "\n\n" 329 331 //usage: "Create /var/log/bootchart.tgz with boot chart data\n" 330 //usage: "\nOptions:"331 332 //usage: "\nstart: start background logging; with PROG, run PROG, then kill logging with USR1" 332 333 //usage: "\nstop: send USR1 to all bootchartd processes" … … 340 341 pid_t parent_pid, logger_pid; 341 342 smallint cmd; 343 int process_accounting; 342 344 enum { 343 345 CMD_STOP = 0, … … 373 375 /* Read config file: */ 374 376 sample_period_us = 200 * 1000; 377 process_accounting = 0; 375 378 if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) { 376 379 char* token[2]; … … 381 384 if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1]) 382 385 sample_period_us = atof(token[1]) * 1000000; 386 if (strcmp(token[0], "PROCESS_ACCOUNTING") == 0 && token[1] 387 && (strcmp(token[1], "on") == 0 || strcmp(token[1], "yes") == 0) 388 ) { 389 process_accounting = 1; 390 } 383 391 } 384 392 config_close(parser); 385 }386 if ((int)sample_period_us <= 0)387 sample_period_us = 1; /* prevent division by 0 */393 if ((int)sample_period_us <= 0) 394 sample_period_us = 1; /* prevent division by 0 */ 395 } 388 396 389 397 /* Create logger child: */ … … 413 421 414 422 tempdir = make_tempdir(); 415 do_logging(sample_period_us );416 finalize(tempdir, cmd == CMD_START ? argv[2] : NULL );423 do_logging(sample_period_us, process_accounting); 424 finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, process_accounting); 417 425 return EXIT_SUCCESS; 418 426 } 419 427 420 428 /* parent */ 429 430 USE_FOR_NOMMU(argv[0][0] &= 0x7f); /* undo fork_or_rexec() damage */ 421 431 422 432 if (DO_SIGNAL_SYNC) { … … 442 452 if (pid == 0) { /* child */ 443 453 argv += 2; 444 execvp(argv[0], argv); 445 bb_perror_msg_and_die("can't execute '%s'", argv[0]); 454 BB_EXECVP_or_die(argv); 446 455 } 447 456 /* parent */ -
branches/3.2/mindi-busybox/init/halt.c
r2725 r3232 8 8 */ 9 9 10 //applet:IF_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_DROP))11 //applet:IF_HALT(APPLET_ODDNAME(poweroff, halt, _BB_DIR_SBIN, _BB_SUID_DROP, poweroff))12 //applet:IF_HALT(APPLET_ODDNAME(reboot, halt, _BB_DIR_SBIN, _BB_SUID_DROP, reboot))10 //applet:IF_HALT(APPLET(halt, BB_DIR_SBIN, BB_SUID_DROP)) 11 //applet:IF_HALT(APPLET_ODDNAME(poweroff, halt, BB_DIR_SBIN, BB_SUID_DROP, poweroff)) 12 //applet:IF_HALT(APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot)) 13 13 14 14 //kbuild:lib-$(CONFIG_HALT) += halt.o … … 44 44 //usage:#define halt_full_usage "\n\n" 45 45 //usage: "Halt the system\n" 46 //usage: "\nOptions:"47 46 //usage: "\n -d SEC Delay interval" 48 47 //usage: "\n -n Do not sync" … … 56 55 //usage:#define poweroff_full_usage "\n\n" 57 56 //usage: "Halt and shut off power\n" 58 //usage: "\nOptions:"59 57 //usage: "\n -d SEC Delay interval" 60 58 //usage: "\n -n Do not sync" … … 65 63 //usage:#define reboot_full_usage "\n\n" 66 64 //usage: "Reboot the system\n" 67 //usage: "\nOptions:"68 65 //usage: "\n -d SEC Delay interval" 69 66 //usage: "\n -n Do not sync" … … 75 72 #if ENABLE_FEATURE_WTMP 76 73 #include <sys/utsname.h> 77 #include <utmp.h>78 74 79 75 static void write_wtmp(void) … … 159 155 * 0 == shutdown 160 156 * 6 == reboot */ 161 rc =execlp(CONFIG_TELINIT_PATH,157 execlp(CONFIG_TELINIT_PATH, 162 158 CONFIG_TELINIT_PATH, 163 159 which == 2 ? "6" : "0", 164 160 (char *)NULL 165 161 ); 162 bb_perror_msg_and_die("can't execute '%s'", 163 CONFIG_TELINIT_PATH); 166 164 } 167 165 } -
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) { -
branches/3.2/mindi-busybox/init/mesg.c
r2725 r3232 8 8 */ 9 9 10 //applet:IF_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_DROP))11 12 //kbuild:lib-$(CONFIG_MESG) += mesg.o13 14 10 //config:config MESG 15 11 //config: bool "mesg" … … 18 14 //config: Mesg controls access to your terminal by others. It is typically 19 15 //config: used to allow or disallow other users to write to your terminal 16 //config: 17 //config:config FEATURE_MESG_ENABLE_ONLY_GROUP 18 //config: bool "Enable writing to tty only by group, not by everybody" 19 //config: default y 20 //config: depends on MESG 21 //config: help 22 //config: Usually, ttys are owned by group "tty", and "write" tool is 23 //config: setgid to this group. This way, "mesg y" only needs to enable 24 //config: "write by owning group" bit in tty mode. 25 //config: 26 //config: If you set this option to N, "mesg y" will enable writing 27 //config: by anybody at all. This is not recommended. 28 29 //applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP)) 30 31 //kbuild:lib-$(CONFIG_MESG) += mesg.o 20 32 21 33 //usage:#define mesg_trivial_usage … … 28 40 #include "libbb.h" 29 41 30 #if def USE_TTY_GROUP42 #if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP 31 43 #define S_IWGRP_OR_S_IWOTH S_IWGRP 32 44 #else … … 38 50 { 39 51 struct stat sb; 40 const char *tty;52 mode_t m; 41 53 char c = 0; 42 54 43 55 argv++; 44 56 45 if ( !argv[0]46 || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n'))57 if (argv[0] 58 && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n')) 47 59 ) { 48 tty = xmalloc_ttyname(STDERR_FILENO); 49 if (tty == NULL) { 50 tty = "ttyname"; 51 } else if (stat(tty, &sb) == 0) { 52 mode_t m; 53 if (c == 0) { 54 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); 55 return EXIT_SUCCESS; 56 } 57 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH 58 : sb.st_mode & ~(S_IWGRP|S_IWOTH); 59 if (chmod(tty, m) == 0) { 60 return EXIT_SUCCESS; 61 } 62 } 63 bb_simple_perror_msg_and_die(tty); 60 bb_show_usage(); 64 61 } 65 bb_show_usage(); 62 63 if (!isatty(STDIN_FILENO)) 64 bb_error_msg_and_die("not a tty"); 65 66 xfstat(STDIN_FILENO, &sb, "stderr"); 67 if (c == 0) { 68 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); 69 return EXIT_SUCCESS; 70 } 71 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH 72 : sb.st_mode & ~(S_IWGRP|S_IWOTH); 73 if (fchmod(STDIN_FILENO, m) != 0) 74 bb_perror_nomsg_and_die(); 75 return EXIT_SUCCESS; 66 76 }
Note:
See TracChangeset
for help on using the changeset viewer.