From 963a74f13cfe27380aa14da7b69121a00cb7415a Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 27 Feb 2012 20:52:20 +0000 Subject: [PATCH] Fix a race in top non-interactive mode. Use plain sleep(3) call instead of arming timer and then pausing. If SIGALRM is delivered before pause(3) is entered, top hangs. Submitted by: Andrey Zonov MFC after: 1 week --- contrib/top/top.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/contrib/top/top.c b/contrib/top/top.c index e7e27d54a97..aaab027ef09 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -70,7 +70,6 @@ int pcpu_stats = No; /* signal handling routines */ sigret_t leave(); -sigret_t onalrm(); sigret_t tstop(); #ifdef SIGWINCH sigret_t winch(); @@ -723,12 +722,7 @@ char *argv[]; no_command = Yes; if (!interactive) { - /* set up alarm */ - (void) signal(SIGALRM, onalrm); - (void) alarm((unsigned)delay); - - /* wait for the rest of it .... */ - pause(); + sleep(delay); } else while (no_command) { @@ -1174,11 +1168,3 @@ int status; exit(status); /*NOTREACHED*/ } - -sigret_t onalrm() /* SIGALRM handler */ - -{ - /* this is only used in batch mode to break out of the pause() */ - /* return; */ -} -