Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2021-09-10 00:45:29 +0300
committerJunio C Hamano <gitster@pobox.com>2021-09-10 03:40:02 +0300
commitd9a65b6c0a9171a3ff636e59a3e435eda8f50e5b (patch)
tree974210918a8662b0f70ac6a7825b2703eba2e203 /setup.c
parent225bc32a989d7a22fa6addafd4ce7dcd04675dbf (diff)
setup: use xopen and xdup in sanitize_stdfds
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>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/setup.c b/setup.c
index eb9367ca5c..347d7181ae 100644
--- 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);
}