Skip to contentSkip to conversation

glocktop: Fix a tight loop under nohup

PATCH Superseded Andrew Price 2 participants 2 messages Feb 25, 2016 – Feb 26, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index 43c3c3f..fe6bcc2 100644
@@ -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
#1 lore raw

PATCH 1/1 glocktop: Fix a tight loop under nohup

----- Original Message -----

Quoted 34 lines

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 -1
index 43c3c3f..fe6bcc2 100644
@@ -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