/*
- * Copyright (c) 1996, 1998-2004 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
# include <floss.h>
#endif
-#include "config.h"
+#include <config.h>
#include <sys/types.h>
#include <sys/param.h>
#include "sudo.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: tgetpass.c,v 1.111 2004/06/06 23:58:11 millert Exp $";
+__unused static const char rcsid[] = "$Sudo: tgetpass.c,v 1.111.2.4 2007/10/08 16:01:10 millert Exp $";
#endif /* lint */
#ifndef TCSASOFT
# define TERM termios
# define tflags c_lflag
# define term_getattr(f, t) tcgetattr(f, t)
-# define term_setattr(f, t) tcsetattr(f, TCSAFLUSH|TCSASOFT, t)
+# define term_setattr(f, t) tcsetattr(f, TCSADRAIN|TCSASOFT, t)
#else
# ifdef HAVE_TERMIO_H
# define TERM termio
(void) fflush(stdout);
restart:
+ signo = 0;
+ pass = NULL;
+ save_errno = 0;
/* Open /dev/tty for reading/writing if possible else use stdin/stderr. */
if (ISSET(flags, TGP_STDIN) ||
(input = output = open(_PATH_TTY, O_RDWR|O_NOCTTY)) == -1) {
memset(&oterm, 0, sizeof(oterm));
}
- if (prompt)
- (void) write(output, prompt, strlen(prompt));
+ /* No output if we are already backgrounded. */
+ if (signo != SIGTTOU && signo != SIGTTIN) {
+ if (prompt)
+ (void) write(output, prompt, strlen(prompt));
- if (timeout > 0)
- alarm(timeout);
- pass = getln(input, buf, sizeof(buf));
- alarm(0);
- save_errno = errno;
+ if (timeout > 0)
+ alarm(timeout);
+ pass = getln(input, buf, sizeof(buf));
+ alarm(0);
+ save_errno = errno;
- if (!ISSET(term.tflags, ECHO))
- (void) write(output, "\n", 1);
+ if (!ISSET(term.tflags, ECHO))
+ (void) write(output, "\n", 1);
+ }
/* Restore old tty settings and signals. */
if (memcmp(&term, &oterm, sizeof(term)) != 0)
case SIGTSTP:
case SIGTTIN:
case SIGTTOU:
- signo = 0;
goto restart;
}
}
- errno = save_errno;
+ if (save_errno)
+ errno = save_errno;
return(pass);
}