diff options
author | guido <guido@FreeBSD.org> | 1998-02-10 20:05:15 +0000 |
---|---|---|
committer | guido <guido@FreeBSD.org> | 1998-02-10 20:05:15 +0000 |
commit | 746524c17bd94942620bbf9bd1deaaf20312bab9 (patch) | |
tree | f3d2fa4bfbfd6c6e31fd3dca0c71140755a794e8 /lib | |
parent | c852558573b47067fef500b0cdd3e3de30f1160a (diff) | |
download | FreeBSD-src-746524c17bd94942620bbf9bd1deaaf20312bab9.zip FreeBSD-src-746524c17bd94942620bbf9bd1deaaf20312bab9.tar.gz |
Do signal handlig he Posix way
Obtained from: NetBSD (after complains from Bruce)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getpass.c | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/lib/libc/gen/getpass.c b/lib/libc/gen/getpass.c index b053d34..e87a5df 100644 --- a/lib/libc/gen/getpass.c +++ b/lib/libc/gen/getpass.c @@ -44,38 +44,8 @@ static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93"; #include <unistd.h> static struct termios oterm, term; -static sig_t ointhandler, oquithandler, otstphandler, oconthandler; static FILE *fp; -static void -sighandler(int signo) -{ - /* restore tty state */ - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm); - - /* restore old sig handlers */ - (void)signal(SIGINT, ointhandler); - (void)signal(SIGQUIT, oquithandler); - (void)signal(SIGTSTP, otstphandler); - - /* resend us this signal */ - (void)kill(getpid(), signo); -} - -/* ARGSUSED */ -static void -sigconthandler(int signo) -{ - /* re-install our signal handlers */ - ointhandler = signal(SIGINT, sighandler); - oquithandler = signal(SIGQUIT, sighandler); - otstphandler = signal(SIGTSTP, sighandler); - - /* turn off echo again */ - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); -} - - char * getpass(prompt) const char *prompt; @@ -84,6 +54,7 @@ getpass(prompt) register char *p; FILE *outfp; static char buf[_PASSWORD_LEN + 1]; + sigset_t oset, nset; /* * read and write to /dev/tty if possible; else read from @@ -94,11 +65,15 @@ getpass(prompt) fp = stdin; } - ointhandler = signal(SIGINT, sighandler); - oquithandler = signal(SIGQUIT, sighandler); - otstphandler = signal(SIGTSTP, sighandler); - oconthandler = signal(SIGCONT, sigconthandler); - + /* + * note - blocking signals isn't necessarily the + * right thing, but we leave it for now. + */ + sigemptyset(&nset); + sigaddset(&nset, SIGINT); + sigaddset(&nset, SIGTSTP); + (void)sigprocmask(SIG_BLOCK, &nset, &oset); + (void)tcgetattr(fileno(fp), &oterm); term = oterm; term.c_lflag &= ~ECHO; @@ -112,11 +87,7 @@ getpass(prompt) (void)write(fileno(outfp), "\n", 1); (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm); - /* restore old sig handlers */ - (void)signal(SIGINT, ointhandler); - (void)signal(SIGQUIT, oquithandler); - (void)signal(SIGTSTP, otstphandler); - (void)signal(SIGCONT, oconthandler); + (void)sigprocmask(SIG_SETMASK, &oset, NULL); if (fp != stdin) (void)fclose(fp); |