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/libbb/vfork_daemon_rexec.c

    r2725 r3232  
    7070
    7171#if ENABLE_FEATURE_PREFER_APPLETS
    72 void FAST_FUNC save_nofork_data(struct nofork_save_area *save)
     72struct nofork_save_area {
     73    jmp_buf die_jmp;
     74    const char *applet_name;
     75    uint32_t option_mask32;
     76    int die_sleep;
     77    uint8_t xfunc_error_retval;
     78};
     79static void save_nofork_data(struct nofork_save_area *save)
    7380{
    7481    memcpy(&save->die_jmp, &die_jmp, sizeof(die_jmp));
     
    7784    save->option_mask32 = option_mask32;
    7885    save->die_sleep = die_sleep;
    79     save->saved = 1;
    80 }
    81 
    82 void FAST_FUNC restore_nofork_data(struct nofork_save_area *save)
     86}
     87static void restore_nofork_data(struct nofork_save_area *save)
    8388{
    8489    memcpy(&die_jmp, &save->die_jmp, sizeof(die_jmp));
     
    8994}
    9095
    91 int FAST_FUNC run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char **argv)
     96int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
    9297{
    9398    int rc, argc;
     99    struct nofork_save_area old;
     100
     101    save_nofork_data(&old);
    94102
    95103    applet_name = APPLET_NAME(applet_no);
    96104
    97105    xfunc_error_retval = EXIT_FAILURE;
    98 
    99     /* Special flag for xfunc_die(). If xfunc will "die"
    100      * in NOFORK applet, xfunc_die() sees negative
    101      * die_sleep and longjmp here instead. */
    102     die_sleep = -1;
    103106
    104107    /* In case getopt() or getopt32() was already called:
     
    131134        argc++;
    132135
     136    /* Special flag for xfunc_die(). If xfunc will "die"
     137     * in NOFORK applet, xfunc_die() sees negative
     138     * die_sleep and longjmp here instead. */
     139    die_sleep = -1;
     140
    133141    rc = setjmp(die_jmp);
    134142    if (!rc) {
     
    139147        /* Finally we can call NOFORK applet's main() */
    140148        rc = applet_main[applet_no](argc, tmp_argv);
    141 
    142     /* The whole reason behind nofork_save_area is that <applet>_main
    143      * may exit non-locally! For example, in hush Ctrl-Z tries
    144      * (modulo bugs) to dynamically create a child (backgrounded task)
    145      * if it detects that Ctrl-Z was pressed when a NOFORK was running.
    146      * Testcase: interactive "rm -i".
    147      * Don't fool yourself into thinking "and <applet>_main() returns
    148      * quickly here" and removing "useless" nofork_save_area code. */
    149 
    150149    } else { /* xfunc died in NOFORK applet */
    151150        /* in case they meant to return 0... */
     
    155154
    156155    /* Restoring some globals */
    157     restore_nofork_data(old);
     156    restore_nofork_data(&old);
    158157
    159158    /* Other globals can be simply reset to defaults */
     
    166165    return rc & 0xff; /* don't confuse people with "exitcodes" >255 */
    167166}
    168 
    169 int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
    170 {
    171     struct nofork_save_area old;
    172 
    173     /* Saving globals */
    174     save_nofork_data(&old);
    175     return run_nofork_applet_prime(&old, applet_no, argv);
    176 }
    177167#endif /* FEATURE_PREFER_APPLETS */
    178168
     
    184174
    185175    if (a >= 0 && (APPLET_IS_NOFORK(a)
    186 #if BB_MMU
     176# if BB_MMU
    187177            || APPLET_IS_NOEXEC(a) /* NOEXEC trick needs fork() */
    188 #endif
     178# endif
    189179    )) {
    190 #if BB_MMU
     180# if BB_MMU
    191181        if (APPLET_IS_NOFORK(a))
    192 #endif
     182# endif
    193183        {
    194184            return run_nofork_applet(a, argv);
    195185        }
    196 #if BB_MMU
     186# if BB_MMU
    197187        /* MMU only */
    198188        /* a->noexec is true */
     
    203193        xfunc_error_retval = EXIT_FAILURE;
    204194        run_applet_no_and_exit(a, argv);
    205 #endif
     195# endif
    206196    }
    207197#endif /* FEATURE_PREFER_APPLETS */
     
    264254        if (fork_or_rexec(argv))
    265255            exit(EXIT_SUCCESS); /* parent */
    266         /* if daemonizing, make sure we detach from stdio & ctty */
     256        /* if daemonizing, detach from stdio & ctty */
    267257        setsid();
    268258        dup2(fd, 0);
    269259        dup2(fd, 1);
    270260        dup2(fd, 2);
     261        if (flags & DAEMON_DOUBLE_FORK) {
     262            /* On Linux, session leader can acquire ctty
     263             * unknowingly, by opening a tty.
     264             * Prevent this: stop being a session leader.
     265             */
     266            if (fork_or_rexec(argv))
     267                exit(EXIT_SUCCESS); /* parent */
     268        }
    271269    }
    272270    while (fd > 2) {
Note: See TracChangeset for help on using the changeset viewer.