aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-20 19:20:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-20 19:20:22 +0000
commite5387a0574a4da88411753c4df959a03629063c9 (patch)
treede01aa892793e9fa1857551256500670280a8daf /libbb
parent037576d77b62186551ad07b10eb46a73144b9f84 (diff)
downloadbusybox-w32-e5387a0574a4da88411753c4df959a03629063c9.tar.gz
busybox-w32-e5387a0574a4da88411753c4df959a03629063c9.tar.bz2
busybox-w32-e5387a0574a4da88411753c4df959a03629063c9.zip
bb_askpass: handle Ctrl-C, restore termoios on Ctrl-C.
sulogin: remove alarm handling, as it is redundant there. code shrink. After all differences cancel out: text data bss dec hex filename 777543 1000 9532 788075 c066b busybox_old 777543 1000 9532 788075 c066b busybox_unstripped
Diffstat (limited to 'libbb')
-rw-r--r--libbb/bb_askpass.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 435314ea0..fd12f92dc 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -17,7 +17,7 @@ static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
17{ 17{
18} 18}
19 19
20char *bb_askpass(int timeout, const char * prompt) 20char *bb_askpass(int timeout, const char *prompt)
21{ 21{
22 /* Was static char[BIGNUM] */ 22 /* Was static char[BIGNUM] */
23 enum { sizeof_passwd = 128 }; 23 enum { sizeof_passwd = 128 };
@@ -25,35 +25,36 @@ char *bb_askpass(int timeout, const char * prompt)
25 25
26 char *ret; 26 char *ret;
27 int i; 27 int i;
28 struct sigaction sa; 28 struct sigaction sa, oldsa;
29 struct termios old, new; 29 struct termios tio, oldtio;
30 30
31 if (!passwd) 31 if (!passwd)
32 passwd = xmalloc(sizeof_passwd); 32 passwd = xmalloc(sizeof_passwd);
33 memset(passwd, 0, sizeof_passwd); 33 memset(passwd, 0, sizeof_passwd);
34 34
35 tcgetattr(STDIN_FILENO, &old); 35 tcgetattr(STDIN_FILENO, &oldtio);
36 tcflush(STDIN_FILENO, TCIFLUSH); 36 tcflush(STDIN_FILENO, TCIFLUSH);
37 tio = oldtio;
38 tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
39 tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
40 tcsetattr(STDIN_FILENO, TCSANOW, &tio);
37 41
38 fputs(prompt, stdout); 42 memset(&sa, 0, sizeof(sa));
39 fflush(stdout); 43 /* sa.sa_flags = 0; - no SA_RESTART! */
40 44 /* SIGINT and SIGALRM will interrupt read below */
41 tcgetattr(STDIN_FILENO, &new); 45 sa.sa_handler = askpass_timeout;
42 new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); 46 sigaction(SIGINT, &sa, &oldsa);
43 new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
44 tcsetattr(STDIN_FILENO, TCSANOW, &new);
45
46 if (timeout) { 47 if (timeout) {
47 sa.sa_flags = 0;
48 sa.sa_handler = askpass_timeout;
49 sigaction(SIGALRM, &sa, NULL); 48 sigaction(SIGALRM, &sa, NULL);
50 alarm(timeout); 49 alarm(timeout);
51 } 50 }
52 51
52 fputs(prompt, stdout);
53 fflush(stdout);
53 ret = NULL; 54 ret = NULL;
54 /* On timeout, read will hopefully be interrupted by SIGALRM, 55 /* On timeout or Ctrl-C, read will hopefully be interrupted,
55 * and we return NULL */ 56 * and we return NULL */
56 if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) { 57 if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {
57 ret = passwd; 58 ret = passwd;
58 i = 0; 59 i = 0;
59 /* Last byte is guaranteed to be 0 60 /* Last byte is guaranteed to be 0
@@ -67,8 +68,9 @@ char *bb_askpass(int timeout, const char * prompt)
67 if (timeout) { 68 if (timeout) {
68 alarm(0); 69 alarm(0);
69 } 70 }
71 sigaction(SIGINT, &oldsa, NULL);
70 72
71 tcsetattr(STDIN_FILENO, TCSANOW, &old); 73 tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
72 bb_putchar('\n'); 74 bb_putchar('\n');
73 fflush(stdout); 75 fflush(stdout);
74 return ret; 76 return ret;