Browse code

FIFO reply pipe goes blocking after it is open now

Jiri Kuthan authored on 22/09/2002 13:11:56
Showing 1 changed files
... ...
@@ -317,6 +317,7 @@ FILE *open_reply_pipe( char *pipe_name )
317 317
 
318 318
 	int fifofd;
319 319
 	FILE *file_handle;
320
+	int flags;
320 321
 
321 322
 	int retries=FIFO_REPLY_RETRIES;
322 323
 
... ...
@@ -326,6 +327,8 @@ FILE *open_reply_pipe( char *pipe_name )
326 327
 	}
327 328
 
328 329
 tryagain:
330
+	/* open non-blocking to make sure that a broken client will not 
331
+	 * block the FIFO server forever */
329 332
 	fifofd=open( pipe_name, O_WRONLY | O_NONBLOCK );
330 333
 	if (fifofd==-1) {
331 334
 		/* retry several times if client is not yet ready for getting
... ...
@@ -350,6 +353,20 @@ tryagain:
350 353
 			pipe_name, strerror(errno));
351 354
 		return 0;
352 355
 	}
356
+	/* we want server blocking for big writes */
357
+	if ( (flags=fcntl(fifofd, F_GETFL, 0))<0) {
358
+		LOG(L_ERR, "ERROR: open_reply_pipe (%s): getfl failed: %s\n",
359
+			pipe_name, strerror(errno));
360
+		return 0;
361
+	}
362
+	flags&=~O_NONBLOCK;
363
+	if (fcntl(fifofd, F_SETFL, flags)<0) {
364
+		LOG(L_ERR, "ERROR: open_reply_pipe (%s): setfl cntl failed: %s\n",
365
+			pipe_name, strerror(errno));
366
+		return 0;
367
+	}
368
+
369
+	/* create an I/O stream */	
353 370
 	file_handle=fdopen( fifofd, "w");
354 371
 	if (file_handle==NULL) {
355 372
 		LOG(L_ERR, "ERROR: open_reply_pipe: open error (%s): %s\n",