[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [lvm-devel] [PATCH] Remove the double open with same mode



Alasdair G Kergon [agk redhat com] wrote:
> On Fri, Mar 12, 2010 at 04:17:56PM -0800, Malahal Naineni wrote:
> >  	if ((open("/dev/null", O_RDONLY) < 0) ||
> > -	    (open("/dev/null", O_WRONLY) < 0) ||
> >  	    (open("/dev/null", O_WRONLY) < 0))
> >  		exit(EXIT_DESC_OPEN_FAILURE);
> 
> stdin, stdout, stderr

Then how about this:

diff -r 8db1b9ee17a8 daemons/dmeventd/dmeventd.c
--- a/daemons/dmeventd/dmeventd.c	Fri Mar 12 16:15:25 2010 -0800
+++ b/daemons/dmeventd/dmeventd.c	Mon Mar 15 10:38:49 2010 -0700
@@ -1650,9 +1650,10 @@ static void _daemonize(void)
 	for (--fd; fd >= 0; fd--)
 		close(fd);
 
-	if ((open("/dev/null", O_RDONLY) < 0) ||
-	    (open("/dev/null", O_WRONLY) < 0) ||
-	    (open("/dev/null", O_WRONLY) < 0))
+	/* open stdin, stdout, stderr */
+	if ((open("/dev/null", O_RDONLY) != 0) ||
+	    (open("/dev/null", O_WRONLY) != 1) ||
+	    (open("/dev/null", O_WRONLY) != 2))
 		exit(EXIT_DESC_OPEN_FAILURE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]