summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:33 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:33 -0700
commit49c2cbe69aa0cb85a2c749ef853eae907d1249ba (patch)
tree5af8c42e781aed15caed395034e7404535df18fd
parentMerge branch 'jc/prefix-filename-allocates' into maint (diff)
parentsetup: use xopen and xdup in sanitize_stdfds (diff)
downloadtgif-49c2cbe69aa0cb85a2c749ef853eae907d1249ba.tar.xz
Merge branch 'rs/setup-use-xopen-and-xdup' into maint
Code clean-up. * rs/setup-use-xopen-and-xdup: setup: use xopen and xdup in sanitize_stdfds
-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);
}