about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-14 17:30:37 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-14 17:30:37 +0200
commit5b44976a2d8bdd1397727663ce019374d6b2730a (patch)
tree2376691581648321ea368e5846541a1ac08abe71
parent6475be926bef4916ce632988a2fa408a637babc7 (diff)
downloaddwm-5b44976a2d8bdd1397727663ce019374d6b2730a.tar.gz
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
-rw-r--r--main.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/main.c b/main.c
index 42c9d8a..b59ff96 100644
--- a/main.c
+++ b/main.c
@@ -190,6 +190,7 @@ main(int argc, char *argv[])
 	fd_set rd;
 	XSetWindowAttributes wa;
 	unsigned int mask;
+	Bool readstdin = True;
 	Window w;
 	XEvent ev;
 
@@ -283,7 +284,8 @@ main(int argc, char *argv[])
 Mainloop:
 	while(running) {
 		FD_ZERO(&rd);
-		FD_SET(STDIN_FILENO, &rd);
+		if(readstdin)
+			FD_SET(STDIN_FILENO, &rd);
 		FD_SET(ConnectionNumber(dpy), &rd);
 
 		i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
@@ -299,11 +301,13 @@ Mainloop:
 						(handler[ev.type])(&ev); /* call handler */
 				}
 			}
-			if(FD_ISSET(STDIN_FILENO, &rd)) {
+			if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) {
 				i = n = 0;
 				for(;;) {
 					if((i = getchar()) == EOF) {
-						stext[0] = 0;
+						/* broken pipe/end of producer */
+						readstdin = False;
+						strcpy(stext, "broken pipe");
 						goto Mainloop;
 					}
 					if(i == '\n' || n >= sizeof(stext) - 1)
ref='#n197'>197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283