Skip to contentSkip to conversation

setup.c: remove needless argument passed to open in sanitize_stdfds

PATCH In review [email protected] 2 participants 2 messages Nov 25, 2018 – Nov 26, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setup.c: remove needless argument passed to open in sanitize_stdfds

From: Pedro de Lyra <[email protected]>

---
According to POSIX manual pages, the open() system call's mode argument specifies the file mode bits to be applied when a new file is created. If neither O_CREAT nor O_TMPFILE is specified, then mode is ignored. So I guess that 0 argument only confuses the reader.

 setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
setup.c +1 -1
index 1be5037f1..d4fd14bb7 100644
@@ -1228,7 +1228,7 @@ const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
 /* if any standard file descriptor is missing open it to /dev/null */
 void sanitize_stdfds(void)
 {
-	int fd = open("/dev/null", O_RDWR, 0);
+	int fd = open("/dev/null", O_RDWR);
 	while (fd != -1 && fd < 2)
 		fd = dup(fd);
 	if (fd == -1)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · [email protected] writes:

According to POSIX manual pages, the open() system call's mode argument specifies the file mode bits to be applied when a new file is created. If neither O_CREAT nor O_TMPFILE is specified, then mode is ignored.

Correct.

While I would say two argument form would have been better if this were a new code, this change is borderline Meh for existing code, because passing 0 there already gives a reasonable sign that we know this parameter does not matter.

If the ignored parameter were 0666 or some other more plausible-as-perm-bits value, the story would be quite different, though.

Thanks.