On Wed, Mar 12, 2014 at 11:09:14PM +0100, Ingo Schwarze wrote:
> I don't really like the warnx(3) call from the bye() ALRM handler
> either, but that's a separate matter.
Me neither.
Maybe something like this instead? (although maybe the done check should
be someplace else?)
Index: lock.c
===================================================================
RCS file: /cvs/src/usr.bin/lock/lock.c,v
retrieving revision 1.27
diff -u -p -r1.27 lock.c
--- lock.c 22 Aug 2013 04:43:40 -0000 1.27
+++ lock.c 12 Mar 2014 23:02:36 -0000
@@ -61,13 +61,14 @@
#define TIMEOUT 15
-void bye(int);
-void hi(int);
+void time_remaining(void);
+void do_timeout(int);
struct timeval timeout;
struct timeval zerotime;
time_t nexttime; /* keep the timeout time */
int no_timeout; /* lock terminal forever */
+sig_atomic_t done;
extern char *__progname;
@@ -162,10 +163,10 @@ main(int argc, char *argv[])
}
/* set signal handlers */
- (void)signal(SIGINT, hi);
- (void)signal(SIGQUIT, hi);
- (void)signal(SIGTSTP, hi);
- (void)signal(SIGALRM, bye);
+ (void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGQUIT, SIG_IGN);
+ (void)signal(SIGTSTP, SIG_IGN);
+ (void)signal(SIGALRM, do_timeout);
ntimer.it_interval = zerotime;
ntimer.it_value = timeout;
@@ -183,10 +184,15 @@ main(int argc, char *argv[])
__progname, ttynam, hostname, sectimeout, date);
}
- for (cnt = 0;;) {
+ for (cnt = 0, done = 0;;) {
+ if (done) {
+ if (!no_timeout)
+ warnx("timeout");
+ _exit(1);
+ }
if (!readpassphrase("Key: ", s, sizeof(s), RPP_ECHO_OFF) ||
*s == '\0') {
- hi(0);
+ time_remaining();
continue;
}
if (usemine) {
@@ -219,9 +225,8 @@ main(int argc, char *argv[])
exit(0);
}
-/*ARGSUSED*/
void
-hi(int signo)
+time_remaining(void)
{
char buf[1024], buf2[1024];
time_t left;
@@ -240,10 +245,7 @@ hi(int signo)
/*ARGSUSED*/
void
-bye(int signo)
+do_timeout(int signo)
{
-
- if (!no_timeout)
- warnx("timeout");
- _exit(1);
+ done = 1;
}