{"thread":{"id":"56476","subject":"[PATCH] setup: use xopen and xdup in sanitize_stdfds","startedAt":"2021-09-09T21:50:39Z","lastAt":"2021-09-09T21:50:39Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"435340","messageId":"2431d9cf-a2ed-ba4e-f7e5-a8427d9f9860@web.de","threadId":"56476","inReplyTo":null,"subject":"[PATCH] setup: use xopen and xdup in sanitize_stdfds","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2021-09-09T21:45:29Z","receivedAt":"2021-09-09T21:50:39Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Replace the catch-all error message with specific ones for opening and\nduplicating by calling the wrappers xopen and xdup.  The code becomes\neasier to follow when error handling is reduced to two letters.\n\nRemove the unnecessary mode parameter while at it -- we expect /dev/null\nto already exist.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n setup.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex eb9367ca5c..347d7181ae 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -1423,11 +1423,9 @@ const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)\n /* if any standard file descriptor is missing open it to /dev/null */\n void sanitize_stdfds(void)\n {\n-\tint fd = open(\"/dev/null\", O_RDWR, 0);\n-\twhile (fd != -1 && fd < 2)\n-\t\tfd = dup(fd);\n-\tif (fd == -1)\n-\t\tdie_errno(_(\"open /dev/null or dup failed\"));\n+\tint fd = xopen(\"/dev/null\", O_RDWR);\n+\twhile (fd < 2)\n+\t\tfd = xdup(fd);\n \tif (fd > 2)\n \t\tclose(fd);\n }\n--\n2.33.0\n"}]}