From d2277e262ff7dd2dd946ea16b93462f3dcdf0447 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Nov 2011 17:19:26 +0100 Subject: nommu: fix cases where we mangle argv[0][0] Signed-off-by: Denys Vlasenko --- init/bootchartd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'init') diff --git a/init/bootchartd.c b/init/bootchartd.c index 5f6121fa4..cc23e6073 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -418,6 +418,8 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) /* parent */ + USE_FOR_NOMMU(argv[0][0] &= 0x7f); /* undo fork_or_rexec() damage */ + if (DO_SIGNAL_SYNC) { /* Wait for logger child to set handlers, then unpause it. * Otherwise with short-lived PROG (e.g. "bootchartd start true") -- cgit v1.2.3-55-g6feb From beb860ac758a5b08f4270da03a5f894f95816109 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Dec 2011 03:31:05 +0100 Subject: init: utmp update of DEAD_PROCESS was misplaced, and could be skipped. Fixing. Signed-off-by: Denys Vlasenko --- init/init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index 645f694c0..864ee6ab8 100644 --- a/init/init.c +++ b/init/init.c @@ -523,15 +523,17 @@ static struct init_action *mark_terminated(pid_t pid) struct init_action *a; if (pid > 0) { + update_utmp(pid, DEAD_PROCESS, + /*tty_name:*/ NULL, + /*username:*/ NULL, + /*hostname:*/ NULL + ); for (a = init_action_list; a; a = a->next) { if (a->pid == pid) { a->pid = 0; return a; } } - update_utmp(pid, DEAD_PROCESS, /*tty_name:*/ NULL, - /*username:*/ NULL, - /*hostname:*/ NULL); } return NULL; } -- cgit v1.2.3-55-g6feb From ef7aa46bc4caa05e39458a47de02d0411e15f8d5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Dec 2011 03:54:28 +0100 Subject: init: code shrink -4 bytes Signed-off-by: Denys Vlasenko --- init/init.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index 864ee6ab8..c540faa70 100644 --- a/init/init.c +++ b/init/init.c @@ -598,7 +598,7 @@ static void new_init_action(uint8_t action_type, const char *command, const char */ nextp = &init_action_list; while ((a = *nextp) != NULL) { - /* Don't enter action if it's already in the list, + /* Don't enter action if it's already in the list. * This prevents losing running RESPAWNs. */ if (strcmp(a->command, command) == 0 @@ -610,14 +610,15 @@ static void new_init_action(uint8_t action_type, const char *command, const char while (*nextp != NULL) nextp = &(*nextp)->next; a->next = NULL; - break; + goto append; } nextp = &a->next; } - if (!a) - a = xzalloc(sizeof(*a)); + a = xzalloc(sizeof(*a)); + /* Append to the end of the list */ + append: *nextp = a; a->action_type = action_type; safe_strncpy(a->command, command, sizeof(a->command)); -- cgit v1.2.3-55-g6feb From c158601d50c2fab56ed0043989ba83fa9cd7f96a Mon Sep 17 00:00:00 2001 From: Quentin Casasnovas Date: Wed, 18 Jan 2012 02:12:13 +0100 Subject: bootchartd: add process accounting feature function old new delta bootchartd_main 962 1088 +126 finalize 294 357 +63 acct - 33 +33 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/0 up/down: 222/0) Total: 222 bytes Signed-off-by: Quentin Casasnovas Signed-off-by: Denys Vlasenko --- init/bootchartd.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'init') diff --git a/init/bootchartd.c b/init/bootchartd.c index cc23e6073..9fd623357 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -208,14 +208,8 @@ static char *make_tempdir(void) return tempdir; } -static void do_logging(unsigned sample_period_us) +static void do_logging(unsigned sample_period_us, int process_accounting) { - //# Enable process accounting if configured - //if [ "$PROCESS_ACCOUNTING" = "yes" ]; then - // [ -e kernel_pacct ] || : > kernel_pacct - // accton kernel_pacct - //fi - FILE *proc_stat = xfopen("proc_stat.log", "w"); FILE *proc_diskstats = xfopen("proc_diskstats.log", "w"); //FILE *proc_netdev = xfopen("proc_netdev.log", "w"); @@ -223,6 +217,11 @@ static void do_logging(unsigned sample_period_us) int look_for_login_process = (getppid() == 1); unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */ + if (process_accounting) { + close(xopen("kernel_pacct", O_WRONLY | O_CREAT | O_TRUNC)); + acct("kernel_pacct"); + } + while (--count && !bb_got_signal) { char *p; int len = open_read_close("/proc/uptime", G.jiffy_line, sizeof(G.jiffy_line)-2); @@ -253,11 +252,9 @@ static void do_logging(unsigned sample_period_us) wait_more: usleep(sample_period_us); } - - // [ -e kernel_pacct ] && accton off } -static void finalize(char *tempdir, const char *prog) +static void finalize(char *tempdir, const char *prog, int process_accounting) { //# Stop process accounting if configured //local pacct= @@ -265,6 +262,9 @@ static void finalize(char *tempdir, const char *prog) FILE *header_fp = xfopen("header", "w"); + if (process_accounting) + acct(NULL); + if (prog) fprintf(header_fp, "profile.process = %s\n", prog); @@ -307,7 +307,7 @@ static void finalize(char *tempdir, const char *prog) fclose(header_fp); /* Package log files */ - system("tar -zcf /var/log/bootchart.tgz header *.log"); // + $pacct + system(xasprintf("tar -zcf /var/log/bootlog.tgz header %s *.log", process_accounting ? "kernel_pacct" : "")); /* Clean up (if we are not in detached tmpfs) */ if (tempdir) { unlink("header"); @@ -315,6 +315,8 @@ static void finalize(char *tempdir, const char *prog) unlink("proc_diskstats.log"); //unlink("proc_netdev.log"); unlink("proc_ps.log"); + if (process_accounting) + unlink("kernel_pacct"); rmdir(tempdir); } @@ -338,6 +340,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) unsigned sample_period_us; pid_t parent_pid, logger_pid; smallint cmd; + int process_accounting; enum { CMD_STOP = 0, CMD_START, @@ -371,6 +374,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) /* Read config file: */ sample_period_us = 200 * 1000; + process_accounting = 0; if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) { char* token[2]; parser_t *parser = config_open2("/etc/bootchartd.conf" + 5, fopen_for_read); @@ -379,11 +383,16 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) while (config_read(parser, token, 2, 0, "#=", PARSE_NORMAL & ~PARSE_COLLAPSE)) { if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1]) sample_period_us = atof(token[1]) * 1000000; + if (strcmp(token[0], "PROCESS_ACCOUNTING") == 0 && token[1] + && (strcmp(token[1], "on") == 0 || strcmp(token[1], "yes") == 0) + ) { + process_accounting = 1; + } } config_close(parser); + if ((int)sample_period_us <= 0) + sample_period_us = 1; /* prevent division by 0 */ } - if ((int)sample_period_us <= 0) - sample_period_us = 1; /* prevent division by 0 */ /* Create logger child: */ logger_pid = fork_or_rexec(argv); @@ -411,8 +420,8 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) putenv((char*)bb_PATH_root_path); tempdir = make_tempdir(); - do_logging(sample_period_us); - finalize(tempdir, cmd == CMD_START ? argv[2] : NULL); + do_logging(sample_period_us, process_accounting); + finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, process_accounting); return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From da2b2da6a708edffcc3b405ab5fd7f3f11af5d33 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Jan 2012 12:15:22 +0100 Subject: init: add a segv debugging aid, disabled by default Signed-off-by: Denys Vlasenko --- init/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'init') diff --git a/init/init.c b/init/init.c index c540faa70..724894698 100644 --- a/init/init.c +++ b/init/init.c @@ -108,6 +108,8 @@ //config: Note that on Linux, init attempts to detect serial terminal and //config: sets TERM to "vt102" if one is found. +#define DEBUG_SEGV_HANDLER 0 + #include "libbb.h" #include #include @@ -118,6 +120,15 @@ #endif #include "reboot.h" /* reboot() constants */ +#if DEBUG_SEGV_HANDLER +# undef _GNU_SOURCE +# define _GNU_SOURCE 1 +# undef __USE_GNU +# define __USE_GNU 1 +# include +# include +#endif + /* Used only for sanitizing purposes in set_sane_term() below. On systems where * the baud rate is stored in a separate field, we can safely disable them. */ #ifndef CBAUD @@ -957,6 +968,33 @@ static int check_delayed_sigs(void) } } +#if DEBUG_SEGV_HANDLER +static +void handle_sigsegv(int sig, siginfo_t *info, void *ucontext) +{ + long ip; + ucontext_t *uc; + + uc = ucontext; + ip = uc->uc_mcontext.gregs[REG_EIP]; + fdprintf(2, "signal:%d address:0x%lx ip:0x%lx\n", + sig, + /* this is void*, but using %p would print "(null)" + * even for ptrs which are not exactly 0, but, say, 0x123: + */ + (long)info->si_addr, + ip); + { + /* glibc extension */ + void *array[50]; + int size; + size = backtrace(array, 50); + backtrace_symbols_fd(array, size, 2); + } + for (;;) sleep(9999); +} +#endif + int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int init_main(int argc UNUSED_PARAM, char **argv) { @@ -964,6 +1002,19 @@ int init_main(int argc UNUSED_PARAM, char **argv) return kill(1, SIGHUP); } +#if DEBUG_SEGV_HANDLER + { + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = handle_sigsegv; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGSEGV, &sa, NULL); + sigaction(SIGILL, &sa, NULL); + sigaction(SIGFPE, &sa, NULL); + sigaction(SIGBUS, &sa, NULL); + } +#endif + if (!DEBUG_INIT) { /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ if (getpid() != 1 -- cgit v1.2.3-55-g6feb