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

Legend:

Unmodified
Added
Removed
  • 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) {
Note: See TracChangeset for help on using the changeset viewer.