Skip to contentSkip to conversation

Remove the double open with same mode

PATCH New Malahal Naineni 5 participants 7 messages Mar 13, 2010 – Mar 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove the double open with same mode

Signed-off-by Malahal Naineni (malahal at us.ibm.com)
daemons/dmeventd/dmeventd.c +0 -1
diff -r 8db1b9ee17a8 -r ee77738483f1 daemons/dmeventd/dmeventd.c
@@ -1651,7 +1651,6 @@ static void _daemonize(void)
 		close(fd);
 
 	if ((open("/dev/null", O_RDONLY) < 0) ||
-	    (open("/dev/null", O_WRONLY) < 0) ||
 	    (open("/dev/null", O_WRONLY) < 0))
 		exit(EXIT_DESC_OPEN_FAILURE);
 
#1 lore raw

PATCH 1/1 Remove the double open with same mode

daemons/dmeventd/dmeventd.c static void _daemonize(void) · line 1655

Quoted 4 lines · Malahal Naineni
daemons/dmeventd/dmeventd.c +0 -1
 	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

Alasdair

#2 lore raw

PATCH 1/1 Remove the double open with same mode

Quoted 10 lines · Alasdair G Kergon

daemons/dmeventd/dmeventd.c static void _daemonize(void) · line 1655

Quoted 4 lines · Malahal Naineni
daemons/dmeventd/dmeventd.c +0 -1
 	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

Alasdair

IMHO it's probably worth to add comment to code, so there will not be similar 'optimizations' proposed in the future.

Zdenek.

#3 lore raw

PATCH 1/1 Remove the double open with same mode

Quoted 9 lines · Zdenek Kabelac
Quoted 8 lines · Alasdair G Kergon

daemons/dmeventd/dmeventd.c static void _daemonize(void) · line 1655

Quoted 4 lines · Malahal Naineni
daemons/dmeventd/dmeventd.c +0 -1
 	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

Quoted 5 lines
Quoted 2 lines

Alasdair

IMHO it's probably worth to add comment to code, so there will not be similar 'optimizations' proposed in the future.

Or dup(2) stdout onto stderr - iirc this is how the code in init/main.c in the kernel is organised and it does make things a little bit more obvious / readable.

Regards,
Bryn.

#4 lore raw

PATCH 1/1 Remove the double open with same mode

In reply to Zdenek Kabelac
Quoted 9 lines · Zdenek Kabelac
Quoted 8 lines · Alasdair G Kergon

daemons/dmeventd/dmeventd.c static void _daemonize(void) · line 1655

Quoted 4 lines · Malahal Naineni
daemons/dmeventd/dmeventd.c +0 -1
 	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

Quoted 7 lines
Quoted 2 lines

Alasdair

IMHO it's probably worth to add comment to code, so there will not be similar 'optimizations' proposed in the future.

Zdenek.

I don't see how its confusing?

Regards,
--Tim

#5 lore raw

PATCH 1/1 Remove the double open with same mode

In reply to Alasdair G Kergon
Quoted 7 lines · Alasdair G Kergon [agk at redhat.com]

Review

Quoted 4 lines · Malahal Naineni
(quoted diff) +0 -1
 	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:

daemons/dmeventd/dmeventd.c +4 -3
diff -r 8db1b9ee17a8 daemons/dmeventd/dmeventd.c
@@ -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);
 
 
#6 lore raw

PATCH 1/1 Remove the double open with same mode

Quoted 6 lines · malahal at us.ibm.com

Then how about this:
diff -r 8db1b9ee17a8 daemons/dmeventd/dmeventd.c

daemons/dmeventd/dmeventd.c +0 -0
@@ -1650,9 +1650,10 @@ static void _daemonize(void)
 	for (--fd; fd >= 0; fd--)

daemons/dmeventd/dmeventd.c static void _daemonize(void) · line 1657

Quoted 10 lines
daemons/dmeventd/dmeventd.c +4 -3
 		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);

Nack. Complete waste of time.

Alasdair.