Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
install.wrapper.c: only exclude our path if we were invoked as "install"
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory M. Turner <[email protected]>
  • Loading branch information
gmt committed Jan 31, 2014
1 parent 95f152c commit 8d7405f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions install.wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ copyxattr(const char *source, const char *target)


static char *
which(const char *mydir)
which(const char *mydir, const char *myargv0basename)
{
char *mycandir = realpath(mydir, NULL); /* canonical value of argv[0]'s dirname */
char *path, *env_path = getenv("PATH"); /* full $PATH string */
Expand All @@ -169,6 +169,11 @@ which(const char *mydir)

struct stat s;

/* If we arv0 says we are "install" then we assume that we're in
* a different directory and someone is playing PATH games.
* Otherwise, we don't care. */
int different_name = strcmp(myargv0basename, "install");

dir = strtok_r(path, ":", &savedptr);

while (dir) {
Expand All @@ -181,7 +186,7 @@ which(const char *mydir)
/* If argv[0]'s canonical dirname == the path's canonical dirname, then we
* skip this path otheriwise we get into an infinite self-invocation.
*/
if (!strcmp(mycandir, candir))
if ((!different_name) && (!strcmp(mycandir, candir)))
goto skip;

file = path_join(candir, "install");
Expand Down Expand Up @@ -231,6 +236,8 @@ main(int argc, char* argv[])

char *portage_xattr_exclude; /* strings of excluded xattr names from $PORTAGE_XATTR_EXCLUDE */

char *argv0copy; /* copy of argv[0] for basename to mangle */

portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
if (portage_xattr_exclude == NULL)
exclude = xstrdup("security.* system.nfs4_acl");
Expand Down Expand Up @@ -290,7 +297,9 @@ main(int argc, char* argv[])
err(1, "fork() failed");

case 0:
install = which(dirname(argv[0]));
if (! argv0copy = strdup(argv[0]))
err(1, "memory allocation or other wierd problem");
install = which(dirname(argv[0]), basename(argv0copy));
argv[0] = install; /* so coreutils' lib/program.c behaves */
execv(install, argv); /* The kernel will free(install). */
err(1, "execv() failed");
Expand Down

0 comments on commit 8d7405f

Please sign in to comment.