git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Sep 30, 2007, 20:10 UTC
Message-ID
<1191183001-5368-6-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<1191183001-5368-5-git-send-email-johannes.sixt@telecom.at>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 builtin-fetch-pack.c |   55 ++++++++++++++-----------------------------------
 1 files changed, 16 insertions(+), 39 deletions(-)
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 19c144d..d0eca2d 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -7,6 +7,7 @@
 #include "pack.h"
 #include "sideband.h"
 #include "fetch-pack.h"
+#include "run-command.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
@@ -499,11 +500,13 @@ static int get_pack(int xd[2], char **pack_lockfile)
 	char hdr_arg[256];
 	const char **av;
 	int do_keep = args.keep_pack;
-	int keep_pipe[2];
+	struct child_process cmd;
 
 	side_pid = setup_sideband(fd, xd);
 
-	av = argv;
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.argv = av = argv;
+
 	*hdr_arg = 0;
 	if (!args.keep_pack && unpack_limit) {
 		struct pack_header header;
@@ -519,8 +522,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
 	}
 
 	if (do_keep) {
-		if (pack_lockfile && pipe(keep_pipe))
-			die("fetch-pack: pipe setup failure: %s", strerror(errno));
+		if (pack_lockfile)
+			cmd.out = -1;
 		*av++ = "index-pack";
 		*av++ = "--stdin";
 		if (!args.quiet && !args.no_progress)
@@ -544,43 +547,17 @@ static int get_pack(int xd[2], char **pack_lockfile)
 		*av++ = hdr_arg;
 	*av++ = NULL;
 
-	pid = fork();
-	if (pid < 0)
+	cmd.in = fd[0];
+	cmd.git_cmd = 1;
+	if (start_command(&cmd))
 		die("fetch-pack: unable to fork off %s", argv[0]);
-	if (!pid) {
-		dup2(fd[0], 0);
-		if (do_keep && pack_lockfile) {
-			dup2(keep_pipe[1], 1);
-			close(keep_pipe[0]);
-			close(keep_pipe[1]);
-		}
-		close(fd[0]);
-		close(fd[1]);
-		execv_git_cmd(argv);
-		die("%s exec failed", argv[0]);
-	}
-	close(fd[0]);
 	close(fd[1]);
-	if (do_keep && pack_lockfile) {
-		close(keep_pipe[1]);
-		*pack_lockfile = index_pack_lockfile(keep_pipe[0]);
-		close(keep_pipe[0]);
-	}
-	while (waitpid(pid, &status, 0) < 0) {
-		if (errno != EINTR)
-			die("waiting for %s: %s", argv[0], strerror(errno));
-	}
-	if (WIFEXITED(status)) {
-		int code = WEXITSTATUS(status);
-		if (code)
-			die("%s died with error code %d", argv[0], code);
-		return 0;
-	}
-	if (WIFSIGNALED(status)) {
-		int sig = WTERMSIG(status);
-		die("%s died of signal %d", argv[0], sig);
-	}
-	die("%s died of unnatural causes %d", argv[0], status);
+	if (do_keep && pack_lockfile)
+		*pack_lockfile = index_pack_lockfile(cmd.out);
+
+	if (finish_command(&cmd))
+		die("%s failed", argv[0]);
+	return 0;
 }
 
 static struct ref *do_fetch_pack(int fd[2],
-- 
1.5.3.3.1134.gee562
Previous: Johannes SixtNext: Johannes Schindelin
Message 6 of 30 in “fork/exec removal series”
  1. 0/5 fork/exec removal seriesJohannes Sixt, Sep 30, 2007
  2. 1/5 Change git_connect() to return a struct child_process instead of a pid_t.Johannes Sixt, Sep 30, 2007
  3. 2/5 Use start_command() in git_connect() instead of explicit fork/exec.Johannes Sixt, Sep 30, 2007
  4. 3/5 Use start_command() to run the filter instead of explicit fork/exec.Johannes Sixt, Sep 30, 2007
  5. 4/5 Use run_command() to spawn external diff programs instead of fork/exec.Johannes Sixt, Sep 30, 2007
  6. 5/5 Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.Johannes Sixt, Sep 30, 2007
  7. Johannes SchindelinSep 30, 2007
  8. Johannes SchindelinSep 30, 2007
  9. Junio C HamanoSep 30, 2007
  10. Johannes SixtSep 30, 2007
  11. 0/5 fork/exec removal seriesJohannes Sixt, Oct 3, 2007
  12. 1/5 Change git_connect() to return a struct child_process instead of a pid_t.Johannes Sixt, Oct 3, 2007
  13. 2/5 Use start_command() in git_connect() instead of explicit fork/exec.Johannes Sixt, Oct 3, 2007
  14. 3/5 Use start_command() to run the filter instead of explicit fork/exec.Johannes Sixt, Oct 3, 2007
  15. 4/5 Use run_command() to spawn external diff programs instead of fork/exec.Johannes Sixt, Oct 3, 2007
  16. 5/5 Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.Johannes Sixt, Oct 3, 2007
  17. Junio C HamanoOct 4, 2007
  18. Johannes SixtOct 4, 2007
  19. Johannes SixtOct 4, 2007
  20. Johannes SixtOct 1, 2007
  21. Junio C HamanoOct 1, 2007
  22. Johannes SixtOct 1, 2007
  23. Junio C HamanoOct 2, 2007
  24. Johannes SchindelinSep 30, 2007
  25. Junio C HamanoSep 30, 2007
  26. Johannes SchindelinSep 30, 2007
  27. Johannes SixtSep 30, 2007
  28. Johannes SchindelinSep 30, 2007
  29. Johannes SixtOct 1, 2007
  30. David KastrupOct 1, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.