glocktop: Fix a tight loop under nohup
PATCH 1/1 glocktop: Fix a tight loop under nohup
When glocktop is run under nohup, it redirects /dev/null to stdin, which flags up EOF and causes the file descriptor to always be in a ready state when select()ed. This causes select() to return immediately instead of timing out after the refresh delay.
Make sure to sleep for the refresh delay on EOF to avoid getting into a tight loop when running under nohup.
--- gfs2/glocktop/glocktop.c | 9 +++++++++ 1 file changed, 9 insertions(+)
gfs2/glocktop/glocktop.c +9 -0
@@ -1856,6 +1856,15 @@ int main(int argc, char **argv)if (refresh_time <1 ) refresh_time =1 ;break ; +/* We can get an EOF if the user hits ^D or if +/dev/null is redirected to stdin, such as when +running under nohup. It should be safe to assume the +latter since ^D shouldn't be expected to do anything +useful. In that case, select() returns immediately +so we need to enforce the refresh delay with a sleep */ +case EOF : +sleep (refresh_time); +break ; } } iters_done++;
Signature · 1 line
2.4.3
PATCH 1/1 glocktop: Fix a tight loop under nohup
----- Original Message -----
Quoted 34 lines
When glocktop is run under nohup, it redirects
/dev/nullto stdin, which flags up EOF and causes the file descriptor to always be in a ready state when select()ed. This causesselect()to return immediately instead of timing out after the refresh delay.Make sure to sleep for the refresh delay on EOF to avoid getting into a tight loop when running under nohup.
Signed-off-by Andrew Price <[email protected]>--- gfs2/glocktop/glocktop.c | 9 +++++++++ 1 file changed, 9 insertions(+)gfs2/glocktop/glocktop.c +9
-1@@ -1856,6 +1856,15 @@ int main(int argc, char **argv)if (refresh_time <1 ) refresh_time =1 ;break ; +/* We can get an EOF if the user hits ^D or if +/dev/null is redirected to stdin, such as when +running under nohup. It should be safe to assume the +latter since ^D shouldn't be expected to do anything +useful. In that case, select() returns immediately +so we need to enforce the refresh delay with a sleep */ +case EOF : +sleep (refresh_time); +break ; } } iters_done++; --
Quoted 3 lines
2.4.3
ACK
Bob Peterson