From: "Scott R Parish" <srp@srparish.net>
To: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>, git@vger.kernel.org
Subject: Re: [PATCH] When exec'ing sub-commands, fall back on execvp (thePATH)
Date: Sat, 20 Oct 2007 03:12:17 -0500 (CDT) [thread overview]
Message-ID: <1192867937.v2.fusewebmail-240137@f> (raw)
Yeah, that seems to work fine. The theoretical drawback to this approach
is that it could possibly effect the order in which the paths are tried.
For instance, if a user did "export GIT_EXEC_PATH=", then the
builtin_exec_path wouldn't be tried before the PATH. (i doubt that it
would be a problem, but thought i should note it)
sRp
----- Original Message -----
Subject: Re: [PATCH] When exec'ing sub-commands, fall back on execvp
(thePATH)
Date: Sat, October 20, 2007 0:30
From: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>
> Hi,
>
> On Fri, 19 Oct 2007, Scott Parish wrote:
>
> > 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;
> > }
>
> I am not sure that this is elegant enough: Something like this (completely
> untested) might be better:
>
> diff --git a/exec_cmd.c b/exec_cmd.c
> index 9b74ed2..c928f37 100644
> --- a/exec_cmd.c
> +++ b/exec_cmd.c
> @@ -36,7 +36,8 @@ int execv_git_cmd(const char **argv)
> int i;
> const char *paths[] = { current_exec_path,
> getenv(EXEC_PATH_ENVIRONMENT),
> - builtin_exec_path };
> + builtin_exec_path,
> + "" };
>
> for (i = 0; i < ARRAY_SIZE(paths); ++i) {
> size_t len;
> @@ -44,9 +45,12 @@ int execv_git_cmd(const char **argv)
> const char *exec_dir = paths[i];
> const char *tmp;
>
> - if (!exec_dir || !*exec_dir) continue;
> + if (!exec_dir) continue;
>
> - if (*exec_dir != '/') {
> + if (!*exec_dir)
> + /* try PATH */
> + *git_command = '\0';
> + else if (*exec_dir != '/') {
> if (!getcwd(git_command, sizeof(git_command))) {
> fprintf(stderr, "git: cannot determine "
> "current directory: %s\n",
> @@ -81,7 +85,7 @@ int execv_git_cmd(const char **argv)
>
> len = strlen(git_command);
> rc = snprintf(git_command + len, sizeof(git_command) -
len,
> - "/git-%s", argv[0]);
> + "%sgit-%s", *exec_dir ? "/" : "", argv[0]);
> if (rc < 0 || rc >= sizeof(git_command) - len) {
> fprintf(stderr,
> "git: command name given is too long.\n");
>
> Ciao,
> Dscho
>
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
next reply other threads:[~2007-10-20 8:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-20 8:12 Scott R Parish [this message]
2007-10-20 20:25 ` [PATCH] When exec'ing sub-commands, fall back on execvp (thePATH) Johannes Schindelin
2007-10-20 20:57 ` Scott Parish
2007-10-20 22:00 ` [PATCH] execv_git_cmd(): also try PATH if everything else fails Johannes Schindelin
2007-10-21 2:36 ` Shawn O. Pearce
2007-10-21 21:59 ` Johannes Schindelin
2007-10-22 4:21 ` Shawn O. Pearce
2007-10-22 10:35 ` Johannes Schindelin
2007-10-23 4:34 ` Shawn O. Pearce
2007-10-23 11:12 ` Johannes Schindelin
2007-10-22 14:36 ` Scott Parish
2007-10-22 15:19 ` Andreas Ericsson
2007-10-22 15:36 ` Johannes Sixt
2007-10-23 11:12 ` Andreas Ericsson
2007-10-23 15:29 ` Johannes Sixt
2007-10-21 18:21 ` Scott Parish
2007-10-21 22:02 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1192867937.v2.fusewebmail-240137@f \
--to=srp@srparish.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).