summaryrefslogtreecommitdiff
path: root/t/helper/test-run-command.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-12-10 21:11:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-10 21:11:42 (GMT)
commit55d607d85b4c22fe2091102ed1eb907ea29b956a (patch)
tree15d39f4c879ca2ee09353de0ea98dc86cd298bb7 /t/helper/test-run-command.c
parent7c887142621106a303a321b51b1958112ed2bf24 (diff)
parent3ba3720b3f187644ac0186a4637898f8e8f85a91 (diff)
downloadgit-55d607d85b4c22fe2091102ed1eb907ea29b956a.zip
git-55d607d85b4c22fe2091102ed1eb907ea29b956a.tar.gz
git-55d607d85b4c22fe2091102ed1eb907ea29b956a.tar.bz2
Merge branch 'js/mingw-inherit-only-std-handles'
Work around a issue where a FD that is left open when spawning a child process and is kept open in the child can interfere with the operation in the parent process on Windows. * js/mingw-inherit-only-std-handles: mingw: forbid translating ERROR_SUCCESS to an errno value mingw: do set `errno` correctly when trying to restrict handle inheritance mingw: restrict file handle inheritance only on Windows 7 and later mingw: spawned processes need to inherit only standard handles mingw: work around incorrect standard handles mingw: demonstrate that all file handles are inherited by child processes
Diffstat (limited to 't/helper/test-run-command.c')
-rw-r--r--t/helper/test-run-command.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c
index 7243289..1646aa2 100644
--- a/t/helper/test-run-command.c
+++ b/t/helper/test-run-command.c
@@ -328,6 +328,46 @@ static int quote_echo(int argc, const char **argv)
return 0;
}
+static int inherit_handle(const char *argv0)
+{
+ struct child_process cp = CHILD_PROCESS_INIT;
+ char path[PATH_MAX];
+ int tmp;
+
+ /* First, open an inheritable handle */
+ xsnprintf(path, sizeof(path), "out-XXXXXX");
+ tmp = xmkstemp(path);
+
+ argv_array_pushl(&cp.args,
+ "test-tool", argv0, "inherited-handle-child", NULL);
+ cp.in = -1;
+ cp.no_stdout = cp.no_stderr = 1;
+ if (start_command(&cp) < 0)
+ die("Could not start child process");
+
+ /* Then close it, and try to delete it. */
+ close(tmp);
+ if (unlink(path))
+ die("Could not delete '%s'", path);
+
+ if (close(cp.in) < 0 || finish_command(&cp) < 0)
+ die("Child did not finish");
+
+ return 0;
+}
+
+static int inherit_handle_child(void)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ if (strbuf_read(&buf, 0, 0) < 0)
+ die("Could not read stdin");
+ printf("Received %s\n", buf.buf);
+ strbuf_release(&buf);
+
+ return 0;
+}
+
int cmd__run_command(int argc, const char **argv)
{
struct child_process proc = CHILD_PROCESS_INIT;
@@ -335,6 +375,10 @@ int cmd__run_command(int argc, const char **argv)
if (argc > 1 && !strcmp(argv[1], "testsuite"))
exit(testsuite(argc - 1, argv + 1));
+ if (!strcmp(argv[1], "inherited-handle"))
+ exit(inherit_handle(argv[0]));
+ if (!strcmp(argv[1], "inherited-handle-child"))
+ exit(inherit_handle_child());
if (argc >= 2 && !strcmp(argv[1], "quote-stress-test"))
return !!quote_stress_test(argc - 1, argv + 1);