Browse code

- flush & switch to unbuffered std. file descriptors before forking

Andrei Pelinescu-Onciul authored on 28/06/2004 15:41:21
Showing 1 changed files
... ...
@@ -436,7 +436,12 @@ int daemonize(char*  name)
436 436
 
437 437
 	p=-1;
438 438
 
439
-
439
+	/* flush std file descriptors to avoid flushes after fork
440
+	 *  (same message appearing multiple times)
441
+	 *  and switch to unbuffered
442
+	 */
443
+	setbuf(stdout, 0);
444
+	setbuf(stderr, 0);
440 445
 	if (chroot_dir&&(chroot(chroot_dir)<0)){
441 446
 		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
442 447
 		goto error;