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


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/init
Files:
4 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 */
  • branches/3.2/mindi-busybox/init/halt.c

    r2725 r3232  
    88 */
    99
    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))
    1313
    1414//kbuild:lib-$(CONFIG_HALT) += halt.o
     
    4444//usage:#define halt_full_usage "\n\n"
    4545//usage:       "Halt the system\n"
    46 //usage:     "\nOptions:"
    4746//usage:     "\n    -d SEC  Delay interval"
    4847//usage:     "\n    -n  Do not sync"
     
    5655//usage:#define poweroff_full_usage "\n\n"
    5756//usage:       "Halt and shut off power\n"
    58 //usage:     "\nOptions:"
    5957//usage:     "\n    -d SEC  Delay interval"
    6058//usage:     "\n    -n  Do not sync"
     
    6563//usage:#define reboot_full_usage "\n\n"
    6664//usage:       "Reboot the system\n"
    67 //usage:     "\nOptions:"
    6865//usage:     "\n    -d SEC  Delay interval"
    6966//usage:     "\n    -n  Do not sync"
     
    7572#if ENABLE_FEATURE_WTMP
    7673#include <sys/utsname.h>
    77 #include <utmp.h>
    7874
    7975static void write_wtmp(void)
     
    159155                 * 0 == shutdown
    160156                 * 6 == reboot */
    161                 rc = execlp(CONFIG_TELINIT_PATH,
     157                execlp(CONFIG_TELINIT_PATH,
    162158                        CONFIG_TELINIT_PATH,
    163159                        which == 2 ? "6" : "0",
    164160                        (char *)NULL
    165161                );
     162                bb_perror_msg_and_die("can't execute '%s'",
     163                        CONFIG_TELINIT_PATH);
    166164            }
    167165        }
  • branches/3.2/mindi-busybox/init/init.c

    r2725 r3232  
    1010 */
    1111
    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))
    1414
    1515//kbuild:lib-$(CONFIG_INIT) += init.o
     
    109109//config:     sets TERM to "vt102" if one is found.
    110110
     111#define DEBUG_SEGV_HANDLER 0
     112
    111113#include "libbb.h"
    112114#include <syslog.h>
     
    114116#include <sys/resource.h>
    115117#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>
    120120#endif
    121121#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
    122131
    123132/* Used only for sanitizing purposes in set_sane_term() below. On systems where
     
    402411    int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
    403412
     413    command += dash;
     414
    404415    /* See if any special /bin/sh requiring characters are present */
    405416    if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
    406         strcpy(buf, "exec ");
    407         strcpy(buf + 5, command + dash); /* excluding "-" */
     417        sprintf(buf, "exec %s", command); /* excluding "-" */
    408418        /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
    409419        cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
     
    411421        cmd[2] = buf;
    412422        cmd[3] = NULL;
     423        command = LIBBB_DEFAULT_LOGIN_SHELL + 1;
    413424    } else {
    414425        /* Convert command (char*) into cmd (char**, one word per string) */
    415426        char *word, *next;
    416427        int i = 0;
    417         next = strcpy(buf, command); /* including "-" */
     428        next = strcpy(buf, command - dash); /* command including "-" */
     429        command = next + dash;
    418430        while ((word = strsep(&next, " \t")) != NULL) {
    419431            if (*word != '\0') { /* not two spaces/tabs together? */
     
    426438    /* If we saw leading "-", it is interactive shell.
    427439     * 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) {
    430442        /* _Attempt_ to make stdin a controlling tty. */
    431         if (ENABLE_FEATURE_INIT_SCTTY)
    432             ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
    433     }
    434     BB_EXECVP(cmd[0] + dash, cmd);
    435     message(L_LOG | L_CONSOLE, "can't run '%s': %s", cmd[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));
    436448    /* returns if execvp fails */
    437449}
     
    509521    /* Log the process name and args */
    510522    message(L_LOG, "starting pid %d, tty '%s': '%s'",
    511               getpid(), a->terminal, a->command);
     523            getpid(), a->terminal, a->command);
    512524
    513525    /* Now run it.  The new program will take over this PID,
     
    523535
    524536    if (pid > 0) {
     537        update_utmp(pid, DEAD_PROCESS,
     538                /*tty_name:*/ NULL,
     539                /*username:*/ NULL,
     540                /*hostname:*/ NULL
     541        );
    525542        for (a = init_action_list; a; a = a->next) {
    526543            if (a->pid == pid) {
     
    529546            }
    530547        }
    531         update_utmp(pid, DEAD_PROCESS, /*tty_name:*/ NULL,
    532                 /*username:*/ NULL,
    533                 /*hostname:*/ NULL);
    534548    }
    535549    return NULL;
     
    596610    nextp = &init_action_list;
    597611    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.
    599613         * This prevents losing running RESPAWNs.
    600614         */
     
    608622                nextp = &(*nextp)->next;
    609623            a->next = NULL;
    610             break;
     624            goto append;
    611625        }
    612626        nextp = &a->next;
    613627    }
    614628
    615     if (!a)
    616         a = xzalloc(sizeof(*a));
     629    a = xzalloc(sizeof(*a));
     630
    617631    /* Append to the end of the list */
     632 append:
    618633    *nextp = a;
    619634    a->action_type = action_type;
     
    954969}
    955970
     971#if DEBUG_SEGV_HANDLER
     972static
     973void 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
    956998int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    957999int init_main(int argc UNUSED_PARAM, char **argv)
     
    9601002        return kill(1, SIGHUP);
    9611003    }
     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
    9621017
    9631018    if (!DEBUG_INIT) {
  • branches/3.2/mindi-busybox/init/mesg.c

    r2725 r3232  
    88 */
    99
    10 //applet:IF_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
    11 
    12 //kbuild:lib-$(CONFIG_MESG) += mesg.o
    13 
    1410//config:config MESG
    1511//config:   bool "mesg"
     
    1814//config:     Mesg controls access to your terminal by others. It is typically
    1915//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
    2032
    2133//usage:#define mesg_trivial_usage
     
    2840#include "libbb.h"
    2941
    30 #ifdef USE_TTY_GROUP
     42#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
    3143#define S_IWGRP_OR_S_IWOTH  S_IWGRP
    3244#else
     
    3850{
    3951    struct stat sb;
    40     const char *tty;
     52    mode_t m;
    4153    char c = 0;
    4254
    4355    argv++;
    4456
    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'))
    4759    ) {
    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();
    6461    }
    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;
    6676}
Note: See TracChangeset for help on using the changeset viewer.