Files
mtkports/dev-vcs/git/patches/0002-montauk-sanitize-stdfds.patch
2026-08-09 10:47:07 +02:00

31 lines
1.1 KiB
Diff

diff --git a/setup.c b/setup.c
index c3301f5ab..6652c1dff 100644
--- a/setup.c
+++ b/setup.c
@@ -1691,11 +1691,20 @@ 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 = xopen("/dev/null", O_RDWR);
- while (fd < 2)
- fd = xdup(fd);
- if (fd > 2)
- close(fd);
+ /*
+ * MontaukOS: nothing to sanitize, and nothing to sanitize it with.
+ *
+ * This guards against being started with 0/1/2 closed, so that a
+ * later open() cannot land on a standard descriptor and have die()
+ * write its message into a data file. On MontaukOS that cannot
+ * happen: the kernel gives every process the terminal on 0/1/2 (the
+ * libc routes those descriptors to SYS_PUTCHAR/SYS_GETCHAR rather
+ * than to any handle), and a process is spawned, never forked with a
+ * doctored descriptor table.
+ *
+ * The upstream body cannot run in any case -- there is no /dev/null,
+ * so xopen() would die here and take every git invocation with it.
+ */
}
int daemonize(void)