Browse code

- flush & switch to unbuffered std. file descriptors before forking (to avoid having a buffer flush after fork => getting the same message multiple times)

Andrei Pelinescu-Onciul authored on 28/06/2004 15:39:35
Showing 1 changed files
... ...
@@ -68,7 +68,12 @@ int daemonize(char*  name)
68 68
 
69 69
 	p=-1;
70 70
 
71
-
71
+	/* flush std file descriptors to avoid flushes after fork
72
+	 *  (same message appearing multiple times)
73
+	 *  and switch to unbuffered
74
+	 */
75
+	setbuf(stdout, 0);
76
+	setbuf(stderr, 0);
72 77
 	if (chroot_dir&&(chroot(chroot_dir)<0)){
73 78
 		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
74 79
 		goto error;