Răsfoiți Sursa

- 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 21 ani în urmă
părinte
comite
bb7ed2d10b
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      daemonize.c

+ 6 - 1
daemonize.c

@@ -68,7 +68,12 @@ int daemonize(char*  name)
 
 
 	p=-1;
 	p=-1;
 
 
-
+	/* flush std file descriptors to avoid flushes after fork
+	 *  (same message appearing multiple times)
+	 *  and switch to unbuffered
+	 */
+	setbuf(stdout, 0);
+	setbuf(stderr, 0);
 	if (chroot_dir&&(chroot(chroot_dir)<0)){
 	if (chroot_dir&&(chroot(chroot_dir)<0)){
 		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
 		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
 		goto error;
 		goto error;