Deleted Added
full compact
1c1
< /* $OpenBSD: readpassphrase.c,v 1.18 2005/08/08 08:05:34 espie Exp $ */
---
> /* $OpenBSD: readpassphrase.c,v 1.22 2010/01/13 10:20:54 dtucker Exp $ */
4c4
< * Copyright (c) 2000-2002 Todd C. Miller <Todd.Miller@courtesan.com>
---
> * Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
49c49
< static volatile sig_atomic_t signo;
---
> static volatile sig_atomic_t signo[_NSIG];
57c57
< int input, output, save_errno;
---
> int input, output, save_errno, i, need_restart;
70c70,74
< signo = 0;
---
> for (i = 0; i < _NSIG; i++)
> signo[i] = 0;
> nr = -1;
> save_errno = 0;
> need_restart = 0;
120,131c124,140
< if (!(flags & RPP_STDIN))
< (void)write(output, prompt, strlen(prompt));
< end = buf + bufsiz - 1;
< for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
< if (p < end) {
< if ((flags & RPP_SEVENBIT))
< ch &= 0x7f;
< if (isalpha(ch)) {
< if ((flags & RPP_FORCELOWER))
< ch = tolower(ch);
< if ((flags & RPP_FORCEUPPER))
< ch = toupper(ch);
---
> /* No I/O if we are already backgrounded. */
> if (signo[SIGTTOU] != 1 && signo[SIGTTIN] != 1) {
> if (!(flags & RPP_STDIN))
> (void)write(output, prompt, strlen(prompt));
> end = buf + bufsiz - 1;
> p = buf;
> while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
> if (p < end) {
> if ((flags & RPP_SEVENBIT))
> ch &= 0x7f;
> if (isalpha(ch)) {
> if ((flags & RPP_FORCELOWER))
> ch = (char)tolower(ch);
> if ((flags & RPP_FORCEUPPER))
> ch = (char)toupper(ch);
> }
> *p++ = ch;
133d141
< *p++ = ch;
134a143,146
> *p = '\0';
> save_errno = errno;
> if (!(term.c_lflag & ECHO))
> (void)write(output, "\n", 1);
136,139d147
< *p = '\0';
< save_errno = errno;
< if (!(term.c_lflag & ECHO))
< (void)write(output, "\n", 1);
154a163
> (void)sigaction(SIGTTOU, &savettou, NULL);
162,168c171,179
< if (signo) {
< kill(getpid(), signo);
< switch (signo) {
< case SIGTSTP:
< case SIGTTIN:
< case SIGTTOU:
< goto restart;
---
> for (i = 0; i < _NSIG; i++) {
> if (signo[i]) {
> kill(getpid(), i);
> switch (i) {
> case SIGTSTP:
> case SIGTTIN:
> case SIGTTOU:
> need_restart = 1;
> }
170a182,183
> if (need_restart)
> goto restart;
172c185,186
< errno = save_errno;
---
> if (save_errno)
> errno = save_errno;
175c189
<
---
>
189c203
< signo = s;
---
> signo[s] = 1;