Merge branch 'jk/execv-dashed-external'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Jan 2017 23:12:16 +0000 (15:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jan 2017 23:12:16 +0000 (15:12 -0800)
Typing ^C to pager, which usually does not kill it, killed Git and
took the pager down as a collateral damage in certain process-tree
structure. This has been fixed.

* jk/execv-dashed-external:
execv_dashed_external: wait for child on signal death
execv_dashed_external: stop exiting with negative code
execv_dashed_external: use child_process struct

1  2 
git.c
diff --combined git.c
index e4714aadb3e6f38baec6afaee493c15590875684,c8fe6637dfcab2a03f98157a43d1a7cee25da954..b367cf6686029a7b54ff4b3ca3d63be2409904b3
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -434,7 -434,7 +434,7 @@@ static struct cmd_struct commands[] = 
        { "fsck-objects", cmd_fsck, RUN_SETUP },
        { "gc", cmd_gc, RUN_SETUP },
        { "get-tar-commit-id", cmd_get_tar_commit_id },
 -      { "grep", cmd_grep, RUN_SETUP_GENTLY },
 +      { "grep", cmd_grep, RUN_SETUP_GENTLY | SUPPORT_SUPER_PREFIX },
        { "hash-object", cmd_hash_object },
        { "help", cmd_help },
        { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY },
        { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
        { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
        { "stripspace", cmd_stripspace },
 -      { "submodule--helper", cmd_submodule__helper, RUN_SETUP },
 +      { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX},
        { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
        { "tag", cmd_tag, RUN_SETUP },
        { "unpack-file", cmd_unpack_file, RUN_SETUP },
@@@ -575,8 -575,7 +575,7 @@@ static void handle_builtin(int argc, co
  
  static void execv_dashed_external(const char **argv)
  {
-       struct strbuf cmd = STRBUF_INIT;
-       const char *tmp;
+       struct child_process cmd = CHILD_PROCESS_INIT;
        int status;
  
        if (get_super_prefix())
                use_pager = check_pager_config(argv[0]);
        commit_pager_choice();
  
-       strbuf_addf(&cmd, "git-%s", argv[0]);
+       argv_array_pushf(&cmd.args, "git-%s", argv[0]);
+       argv_array_pushv(&cmd.args, argv + 1);
+       cmd.clean_on_exit = 1;
+       cmd.wait_after_clean = 1;
+       cmd.silent_exec_failure = 1;
  
-       /*
-        * argv[0] must be the git command, but the argv array
-        * belongs to the caller, and may be reused in
-        * subsequent loop iterations. Save argv[0] and
-        * restore it on error.
-        */
-       tmp = argv[0];
-       argv[0] = cmd.buf;
-       trace_argv_printf(argv, "trace: exec:");
+       trace_argv_printf(cmd.args.argv, "trace: exec:");
  
        /*
-        * if we fail because the command is not found, it is
-        * OK to return. Otherwise, we just pass along the status code.
+        * If we fail because the command is not found, it is
+        * OK to return. Otherwise, we just pass along the status code,
+        * or our usual generic code if we were not even able to exec
+        * the program.
         */
-       status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT);
-       if (status >= 0 || errno != ENOENT)
+       status = run_command(&cmd);
+       if (status >= 0)
                exit(status);
-       argv[0] = tmp;
-       strbuf_release(&cmd);
+       else if (errno != ENOENT)
+               exit(128);
  }
  
  static int run_argv(int *argcp, const char ***argv)