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/shell/shell_common.c

    r2725 r3232  
    1919#include "libbb.h"
    2020#include "shell_common.h"
     21#include <sys/resource.h> /* getrlimit */
    2122
    2223const char defifsvar[] ALIGN1 = "IFS= \t\n";
     
    3738/* read builtin */
    3839
     40/* Needs to be interruptible: shell mush handle traps and shell-special signals
     41 * while inside read. To implement this, be sure to not loop on EINTR
     42 * and return errno == EINTR reliably.
     43 */
    3944//TODO: use more efficient setvar() which takes a pointer to malloced "VAR=VAL"
    4045//string. hush naturally has it, and ash has setvareq().
     
    5257)
    5358{
     59    unsigned err;
    5460    unsigned end_ms; /* -t TIMEOUT */
    5561    int fd; /* -u FD */
     
    6268    int startword;
    6369    smallint backslash;
     70
     71    errno = err = 0;
    6472
    6573    pp = argv;
     
    132140        if (nchars) {
    133141            tty.c_lflag &= ~ICANON;
    134             tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
     142            // Setting it to more than 1 breaks poll():
     143            // it blocks even if there's data. !??
     144            //tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
     145            /* reads would block only if < 1 char is available */
     146            tty.c_cc[VMIN] = 1;
     147            /* no timeout (reads block forever) */
     148            tty.c_cc[VTIME] = 0;
    135149        }
    136150        if (read_flags & BUILTIN_READ_SILENT) {
     
    153167    do {
    154168        char c;
    155 
     169        struct pollfd pfd[1];
     170        int timeout;
     171
     172        if ((bufpos & 0xff) == 0)
     173            buffer = xrealloc(buffer, bufpos + 0x101);
     174
     175        timeout = -1;
    156176        if (end_ms) {
    157             int timeout;
    158             struct pollfd pfd[1];
    159 
    160             pfd[0].fd = fd;
    161             pfd[0].events = POLLIN;
    162177            timeout = end_ms - (unsigned)monotonic_ms();
    163             if (timeout <= 0 /* already late? */
    164              || safe_poll(pfd, 1, timeout) != 1 /* no? wait... */
    165             ) { /* timed out! */
     178            if (timeout <= 0) { /* already late? */
    166179                retval = (const char *)(uintptr_t)1;
    167180                goto ret;
     
    169182        }
    170183
    171         if ((bufpos & 0xff) == 0)
    172             buffer = xrealloc(buffer, bufpos + 0x100);
    173         if (nonblock_safe_read(fd, &buffer[bufpos], 1) != 1) {
     184        /* We must poll even if timeout is -1:
     185         * we want to be interrupted if signal arrives,
     186         * regardless of SA_RESTART-ness of that signal!
     187         */
     188        errno = 0;
     189        pfd[0].fd = fd;
     190        pfd[0].events = POLLIN;
     191        if (poll(pfd, 1, timeout) != 1) {
     192            /* timed out, or EINTR */
     193            err = errno;
     194            retval = (const char *)(uintptr_t)1;
     195            goto ret;
     196        }
     197        if (read(fd, &buffer[bufpos], 1) != 1) {
     198            err = errno;
    174199            retval = (const char *)(uintptr_t)1;
    175200            break;
    176201        }
     202
    177203        c = buffer[bufpos];
    178204        if (c == '\0')
     
    241267    if (read_flags & BUILTIN_READ_SILENT)
    242268        tcsetattr(fd, TCSANOW, &old_tty);
     269
     270    errno = err;
    243271    return retval;
    244272}
     
    287315    { RLIMIT_LOCKS,     0,  'w',    "locks" },
    288316#endif
     317#ifdef RLIMIT_NICE
     318    { RLIMIT_NICE,      0,  'e',    "scheduling priority" },
     319#endif
     320#ifdef RLIMIT_RTPRIO
     321    { RLIMIT_RTPRIO,    0,  'r',    "real-time priority" },
     322#endif
    289323};
    290324
     
    328362#ifdef RLIMIT_LOCKS
    329363            "w::"
     364#endif
     365#ifdef RLIMIT_NICE
     366            "e::"
     367#endif
     368#ifdef RLIMIT_RTPRIO
     369            "r::"
    330370#endif
    331371            ;
     
    369409    /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
    370410
    371         argc = 1;
    372         while (argv[argc])
    373                 argc++;
     411    argc = 1;
     412    while (argv[argc])
     413        argc++;
    374414
    375415    opts = 0;
Note: See TracChangeset for help on using the changeset viewer.