Explorar el Código

- redirect stdin, stdout & stderr ot /dev/null
(this should fix printf in other file descriptors bugs)

Andrei Pelinescu-Onciul hace 23 años
padre
commit
e833d08a63
Se han modificado 3 ficheros con 25 adiciones y 4 borrados
  1. 2 2
      Makefile.defs
  2. 4 0
      TODO
  3. 19 2
      main.c

+ 2 - 2
Makefile.defs

@@ -7,8 +7,8 @@
 #version number
 VERSION = 0
 PATCHLEVEL = 8
-SUBLEVEL =   10
-EXTRAVERSION = 
+SUBLEVEL =   11
+EXTRAVERSION = pre1
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 4 - 0
TODO

@@ -58,3 +58,7 @@ x the same for rpm
 x jku: branch hash computation over canonical values
 0 jku: loop checking
 - jku: try CRC as opposed to MD5
+
+
+- freopen stdin, stdou to /dev/null
+

+ 19 - 2
main.c

@@ -383,9 +383,26 @@ int daemonize(char*  name)
 		}
 	}
 	
+	/* try to replace stdin, stdout & stderr with /dev/null */
+	if (freopen("/dev/null", "r", stdin)==0){
+		LOG(L_ERR, "unable to replace stdin with /dev/null: %s\n",
+				strerror(errno));
+		/* continue, leave it open */
+	};
+	if (freopen("/dev/null", "w", stdout)==0){
+		LOG(L_ERR, "unable to replace stdout with /dev/null: %s\n",
+				strerror(errno));
+		/* continue, leave it open */
+	};
+	/* close stderr only if log_stderr=0 */
+	if ((!log_stderr) &&(freopen("/dev/null", "r", stderr)==0)){
+		LOG(L_ERR, "unable to replace stderr with /dev/null: %s\n",
+				strerror(errno));
+		/* continue, leave it open */
+	};
+	
 	/* close any open file descriptors */
-	for (r=0;r<MAX_FD; r++){
-			if ((r==2) && log_stderr)  continue;
+	for (r=3;r<MAX_FD; r++){
 			close(r);
 	}