Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/bb_askpass.c

    r1765 r2725  
    66 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    77 *
    8  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
    10 
    11 #include <termios.h>
    1210
    1311#include "libbb.h"
    1412
    1513/* do nothing signal handler */
    16 static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
     14static void askpass_timeout(int UNUSED_PARAM ignore)
    1715{
    1816}
    1917
    20 char *bb_askpass(int timeout, const char * prompt)
     18char* FAST_FUNC bb_ask_stdin(const char *prompt)
     19{
     20    return bb_ask(STDIN_FILENO, 0, prompt);
     21}
     22char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
    2123{
    2224    /* Was static char[BIGNUM] */
     
    2628    char *ret;
    2729    int i;
    28     struct sigaction sa;
    29     struct termios old, new;
     30    struct sigaction sa, oldsa;
     31    struct termios tio, oldtio;
     32
     33    tcgetattr(fd, &oldtio);
     34    tcflush(fd, TCIFLUSH);
     35    tio = oldtio;
     36#ifndef IUCLC
     37# define IUCLC 0
     38#endif
     39    tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
     40    tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
     41    tcsetattr(fd, TCSANOW, &tio);
     42
     43    memset(&sa, 0, sizeof(sa));
     44    /* sa.sa_flags = 0; - no SA_RESTART! */
     45    /* SIGINT and SIGALRM will interrupt reads below */
     46    sa.sa_handler = askpass_timeout;
     47    sigaction(SIGINT, &sa, &oldsa);
     48    if (timeout) {
     49        sigaction_set(SIGALRM, &sa);
     50        alarm(timeout);
     51    }
     52
     53    fputs(prompt, stdout);
     54    fflush_all();
    3055
    3156    if (!passwd)
    3257        passwd = xmalloc(sizeof_passwd);
    33     memset(passwd, 0, sizeof_passwd);
    34 
    35     tcgetattr(STDIN_FILENO, &old);
    36     tcflush(STDIN_FILENO, TCIFLUSH);
    37 
    38     fputs(prompt, stdout);
    39     fflush(stdout);
    40 
    41     tcgetattr(STDIN_FILENO, &new);
    42     new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
    43     new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
    44     tcsetattr(STDIN_FILENO, TCSANOW, &new);
    45 
    46     if (timeout) {
    47         sa.sa_flags = 0;
    48         sa.sa_handler = askpass_timeout;
    49         sigaction(SIGALRM, &sa, NULL);
    50         alarm(timeout);
    51     }
    52 
    53     ret = NULL;
    54     /* On timeout, read will hopefully be interrupted by SIGALRM,
    55      * and we return NULL */
    56     if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) {
    57         ret = passwd;
    58         i = 0;
    59         /* Last byte is guaranteed to be 0
    60            (read did not overwrite it) */
    61         do {
    62             if (passwd[i] == '\r' || passwd[i] == '\n')
    63                 passwd[i] = '\0';
    64         } while (passwd[i++]);
     58    ret = passwd;
     59    i = 0;
     60    while (1) {
     61        int r = read(fd, &ret[i], 1);
     62        if (r < 0) {
     63            /* read is interrupted by timeout or ^C */
     64            ret = NULL;
     65            break;
     66        }
     67        if (r == 0 /* EOF */
     68         || ret[i] == '\r' || ret[i] == '\n' /* EOL */
     69         || ++i == sizeof_passwd-1 /* line limit */
     70        ) {
     71            ret[i] = '\0';
     72            break;
     73        }
    6574    }
    6675
     
    6877        alarm(0);
    6978    }
    70 
    71     tcsetattr(STDIN_FILENO, TCSANOW, &old);
    72     putchar('\n');
    73     fflush(stdout);
     79    sigaction_set(SIGINT, &oldsa);
     80    tcsetattr(fd, TCSANOW, &oldtio);
     81    bb_putchar('\n');
     82    fflush_all();
    7483    return ret;
    7584}
Note: See TracChangeset for help on using the changeset viewer.