try to not call signaction for signal 0 and use NSIG if it exists to
determin how many signals there exists, also, only restore those signalhandlers that we got out. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18156 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -43,10 +43,15 @@ intr(int sig)
|
|||||||
intr_flag++;
|
intr_flag++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NSIG
|
||||||
|
#define NSIG 47
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
read_string(const char *prompt, char *buf, size_t len, int echo)
|
read_string(const char *prompt, char *buf, size_t len, int echo)
|
||||||
{
|
{
|
||||||
struct sigaction sigs[47];
|
struct sigaction sigs[NSIG];
|
||||||
|
int oksigs[NSIG];
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
FILE *tty;
|
FILE *tty;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@@ -57,12 +62,16 @@ read_string(const char *prompt, char *buf, size_t len, int echo)
|
|||||||
|
|
||||||
struct termios t_new, t_old;
|
struct termios t_new, t_old;
|
||||||
|
|
||||||
|
memset(&oksigs, 0, sizeof(oksigs));
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = intr;
|
sa.sa_handler = intr;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
for(i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
for(i = 1; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
||||||
if (i != SIGALRM) sigaction(i, &sa, &sigs[i]);
|
if (i != SIGALRM)
|
||||||
|
if (sigaction(i, &sa, &sigs[i]) == 0)
|
||||||
|
oksigs[i] = 1;
|
||||||
|
|
||||||
if((tty = fopen("/dev/tty", "r")) == NULL)
|
if((tty = fopen("/dev/tty", "r")) == NULL)
|
||||||
tty = stdin;
|
tty = stdin;
|
||||||
@@ -103,8 +112,9 @@ read_string(const char *prompt, char *buf, size_t len, int echo)
|
|||||||
if(tty != stdin)
|
if(tty != stdin)
|
||||||
fclose(tty);
|
fclose(tty);
|
||||||
|
|
||||||
for(i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
for(i = 1; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
||||||
if (i != SIGALRM) sigaction(i, &sigs[i], NULL);
|
if (oksigs[i])
|
||||||
|
sigaction(i, &sigs[i], NULL);
|
||||||
|
|
||||||
if(ret)
|
if(ret)
|
||||||
return -3;
|
return -3;
|
||||||
|
Reference in New Issue
Block a user