Browse code

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

Andrei Pelinescu-Onciul authored on 28/11/2002 13:57:59
Showing 3 changed files
... ...
@@ -7,8 +7,8 @@
7 7
 #version number
8 8
 VERSION = 0
9 9
 PATCHLEVEL = 8
10
-SUBLEVEL =   10
11
-EXTRAVERSION = 
10
+SUBLEVEL =   11
11
+EXTRAVERSION = pre1
12 12
 
13 13
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 14
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -58,3 +58,7 @@ x the same for rpm
58 58
 x jku: branch hash computation over canonical values
59 59
 0 jku: loop checking
60 60
 - jku: try CRC as opposed to MD5
61
+
62
+
63
+- freopen stdin, stdou to /dev/null
64
+
... ...
@@ -383,9 +383,26 @@ int daemonize(char*  name)
383 383
 		}
384 384
 	}
385 385
 	
386
+	/* try to replace stdin, stdout & stderr with /dev/null */
387
+	if (freopen("/dev/null", "r", stdin)==0){
388
+		LOG(L_ERR, "unable to replace stdin with /dev/null: %s\n",
389
+				strerror(errno));
390
+		/* continue, leave it open */
391
+	};
392
+	if (freopen("/dev/null", "w", stdout)==0){
393
+		LOG(L_ERR, "unable to replace stdout with /dev/null: %s\n",
394
+				strerror(errno));
395
+		/* continue, leave it open */
396
+	};
397
+	/* close stderr only if log_stderr=0 */
398
+	if ((!log_stderr) &&(freopen("/dev/null", "r", stderr)==0)){
399
+		LOG(L_ERR, "unable to replace stderr with /dev/null: %s\n",
400
+				strerror(errno));
401
+		/* continue, leave it open */
402
+	};
403
+	
386 404
 	/* close any open file descriptors */
387
-	for (r=0;r<MAX_FD; r++){
388
-			if ((r==2) && log_stderr)  continue;
405
+	for (r=3;r<MAX_FD; r++){
389 406
 			close(r);
390 407
 	}
391 408