Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/init/bootchartd.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/init/bootchartd.c

    r2725 r3232  
    44 */
    55
    6 //applet:IF_BOOTCHARTD(APPLET(bootchartd, _BB_DIR_SBIN, _BB_SUID_DROP))
     6//applet:IF_BOOTCHARTD(APPLET(bootchartd, BB_DIR_SBIN, BB_SUID_DROP))
    77
    88//kbuild:lib-$(CONFIG_BOOTCHARTD) += bootchartd.o
     
    209209}
    210210
    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 
     211static void do_logging(unsigned sample_period_us, int process_accounting)
     212{
    219213    FILE *proc_stat = xfopen("proc_stat.log", "w");
    220214    FILE *proc_diskstats = xfopen("proc_diskstats.log", "w");
     
    223217    int look_for_login_process = (getppid() == 1);
    224218    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    }
    225224
    226225    while (--count && !bb_got_signal) {
     
    254253        usleep(sample_period_us);
    255254    }
    256 
    257     // [ -e kernel_pacct ] && accton off
    258 }
    259 
    260 static void finalize(char *tempdir, const char *prog)
     255}
     256
     257static void finalize(char *tempdir, const char *prog, int process_accounting)
    261258{
    262259    //# Stop process accounting if configured
     
    265262
    266263    FILE *header_fp = xfopen("header", "w");
     264
     265    if (process_accounting)
     266        acct(NULL);
    267267
    268268    if (prog)
     
    308308
    309309    /* Package log files */
    310     system("tar -zcf /var/log/bootchart.tgz header *.log"); // + $pacct
     310    system(xasprintf("tar -zcf /var/log/bootlog.tgz header %s *.log", process_accounting ? "kernel_pacct" : ""));
    311311    /* Clean up (if we are not in detached tmpfs) */
    312312    if (tempdir) {
     
    316316        //unlink("proc_netdev.log");
    317317        unlink("proc_ps.log");
     318        if (process_accounting)
     319            unlink("kernel_pacct");
    318320        rmdir(tempdir);
    319321    }
     
    328330//usage:#define bootchartd_full_usage "\n\n"
    329331//usage:       "Create /var/log/bootchart.tgz with boot chart data\n"
    330 //usage:     "\nOptions:"
    331332//usage:     "\nstart: start background logging; with PROG, run PROG, then kill logging with USR1"
    332333//usage:     "\nstop: send USR1 to all bootchartd processes"
     
    340341    pid_t parent_pid, logger_pid;
    341342    smallint cmd;
     343    int process_accounting;
    342344    enum {
    343345        CMD_STOP = 0,
     
    373375    /* Read config file: */
    374376    sample_period_us = 200 * 1000;
     377    process_accounting = 0;
    375378    if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) {
    376379        char* token[2];
     
    381384            if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1])
    382385                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            }
    383391        }
    384392        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    }
    388396
    389397    /* Create logger child: */
     
    413421
    414422        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);
    417425        return EXIT_SUCCESS;
    418426    }
    419427
    420428    /* parent */
     429
     430    USE_FOR_NOMMU(argv[0][0] &= 0x7f); /* undo fork_or_rexec() damage */
    421431
    422432    if (DO_SIGNAL_SYNC) {
     
    442452        if (pid == 0) { /* child */
    443453            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);
    446455        }
    447456        /* parent */
Note: See TracChangeset for help on using the changeset viewer.