]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: use xopen and xdup in sanitize_stdfds
authorRené Scharfe <l.s.r@web.de>
Thu, 9 Sep 2021 21:45:29 +0000 (23:45 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Sep 2021 00:40:02 +0000 (17:40 -0700)
Replace the catch-all error message with specific ones for opening and
duplicating by calling the wrappers xopen and xdup.  The code becomes
easier to follow when error handling is reduced to two letters.

Remove the unnecessary mode parameter while at it -- we expect /dev/null
to already exist.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c

diff --git a/setup.c b/setup.c
index eb9367ca5cbebf6855cd271407fd9533ffced795..347d7181ae907c027f01cbc8ec42a2b64de06ebc 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1423,11 +1423,9 @@ 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);
-       while (fd != -1 && fd < 2)
-               fd = dup(fd);
-       if (fd == -1)
-               die_errno(_("open /dev/null or dup failed"));
+       int fd = xopen("/dev/null", O_RDWR);
+       while (fd < 2)
+               fd = xdup(fd);
        if (fd > 2)
                close(fd);
 }