Git development
 help / color / mirror / Atom feed
* [PATCH] When exec'ing sub-commands, fall back on execvp (the PATH)
@ 2007-10-20  6:44 Scott Parish
  2007-10-20  7:30 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: Scott Parish @ 2007-10-20  6:44 UTC (permalink / raw)
  To: git

 Signed-off-by: Scott R Parish <srp@srparish.net>

---
 exec_cmd.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index 9b74ed2..674c9f3 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -34,15 +34,15 @@ int execv_git_cmd(const char **argv)
 {
 	char git_command[PATH_MAX + 1];
 	int i;
+	int rc;
 	const char *paths[] = { current_exec_path,
 				getenv(EXEC_PATH_ENVIRONMENT),
 				builtin_exec_path };
+	const char *tmp;
+	size_t len;
 
 	for (i = 0; i < ARRAY_SIZE(paths); ++i) {
-		size_t len;
-		int rc;
 		const char *exec_dir = paths[i];
-		const char *tmp;
 
 		if (!exec_dir || !*exec_dir) continue;
 
@@ -106,8 +106,26 @@ int execv_git_cmd(const char **argv)
 
 		argv[0] = tmp;
 	}
-	return -1;
 
+	rc = snprintf(git_command, sizeof(git_command), "git-%s", argv[0]);
+	if (rc < 0 || rc >= sizeof(git_command) - len) {
+		fprintf(stderr, "git: command name given is too long.\n");
+		return -1;
+	}
+
+	tmp = argv[0];
+	argv[0] = git_command;
+
+	trace_argv_printf(argv, -1, "trace: exec:");
+
+	/* execve() can only ever return if it fails */
+	execvp(git_command, (char **)argv);
+
+	trace_printf("trace: exec failed: %s\n", strerror(errno));
+
+	argv[0] = tmp;
+
+	return -1;
 }
 
 
-- 
1.5.3.GIT

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-20  7:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-20  6:44 [PATCH] When exec'ing sub-commands, fall back on execvp (the PATH) Scott Parish
2007-10-20  7:30 ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox