From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 2AF0213877A for ; Sun, 15 Jun 2014 22:09:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 95291E090B; Sun, 15 Jun 2014 22:09:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EAC96E0844 for ; Sun, 15 Jun 2014 22:09:48 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B230F33FC0C for ; Sun, 15 Jun 2014 22:09:47 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 803D9187DE for ; Sun, 15 Jun 2014 22:09:45 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1402870182.8fe175f9c0c592a49eff7941f60d28afc7e02308.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/install-xattr/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/install-xattr/install-xattr.c X-VCS-Directories: misc/install-xattr/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 8fe175f9c0c592a49eff7941f60d28afc7e02308 X-VCS-Branch: master Date: Sun, 15 Jun 2014 22:09:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f5027004-d324-416f-90a5-59aaac013844 X-Archives-Hash: 7a399d2e5fe85e4214d972ccf60a9e18 commit: 8fe175f9c0c592a49eff7941f60d28afc7e02308 Author: Anthony G. Basile gentoo org> AuthorDate: Sun Jun 15 22:09:42 2014 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sun Jun 15 22:09:42 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=8fe175f9 misc/install-xattr: chdir to OLDPWD if we are wrapped by __PORTAGE_HELPER_PATH --- misc/install-xattr/install-xattr.c | 47 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c index 126ffb9..3d70b5e 100644 --- a/misc/install-xattr/install-xattr.c +++ b/misc/install-xattr/install-xattr.c @@ -162,7 +162,7 @@ copyxattr(const char *source, const char *target) static char * -which(char *mypath) +which(char *mypath, char *portage_helper_path) { /* $PATH for system install */ char *path = NULL, *env_path = getenv("PATH"); @@ -175,35 +175,16 @@ which(char *mypath) } else path = xstrdup(env_path); - /* $PORTAGE_BIN_PATH for portage install */ - char *portpath = NULL, *portage_bin_path = getenv("PORTAGE_BIN_PATH"); - - /* If we have a $PORTAGE_BIN_PATH, then assume portage's install is at - * $PORTAGE_BIN_PATH/install. Check if this file exists, and if it does - * set portpath = $PORTAGE_BIN_PATH/install. If it doesn't then set - * portpath = NULL. - */ - if (portage_bin_path != NULL) { - struct stat s; - - portpath = path_join(portage_bin_path, "install"); - portpath = realpath(portpath, NULL); - - if (stat(portpath, &s) == 0) /* If the path exsist but isn't a file/sym link, portpath = NULL */ - if (!S_ISREG(s.st_mode)) - portpath = NULL; - } - char *dir; /* one directory in the colon delimited $PATH string */ - char *canfile; /* candidate install's path = dir + "/install" */ char *canpath; /* candidate install's canonical path */ char *savedptr; /* reentrant context for strtok_r() */ dir = strtok_r(path, ":", &savedptr); while (dir) { - canfile = path_join(dir, "install"); + char *canfile = path_join(dir, "install"); canpath = realpath(canfile, NULL); + free(canfile); /* ignore invalid paths that cannot be canonicalized */ if (!canpath) @@ -218,8 +199,8 @@ which(char *mypath) /* If portage install's canonical path == candidate install's canonical path, * then we skip this path otheriwise we get into an infinite self-invocation. */ - if (portpath) - if (!strcmp(portpath, canpath)) + if (portage_helper_path) + if (!strcmp(portage_helper_path, canpath)) goto skip; /* If the canpath exists and is either a regular file or sym link, @@ -230,7 +211,6 @@ which(char *mypath) if (stat(canpath, &s) == 0) if (S_ISREG(s.st_mode)) { free(path); - free(portpath); return canpath; } @@ -240,8 +220,6 @@ which(char *mypath) dir = strtok_r(NULL, ":", &savedptr); } - free(portpath); - if (env_path == NULL) err(1, "failed to find 'install' in standard utilities path"); else @@ -338,12 +316,25 @@ main(int argc, char* argv[]) first = optind; last = argc - 1; + /* Do we need to chdir to OLDPWD? This is required when we are called my a + * wrapper like ${__PORTAGE_HELPER_PATH} which then passes its directory as + * $PWD and the source directory from which it was called as $OLDPWD. But + * we want the system install to run in the source directory, ie $OLDPWD, + * so we chdir to it. Currently we assume that if __PORTAGE_HELPER_PATH + * is set, then we chdir to oldpwd. + */ + char *oldpwd = getenv("OLDPWD"); + char *portage_helper_path = getenv("__PORTAGE_HELPER_PATH"); + if (portage_helper_path) + chdir(oldpwd); + switch (fork()) { case -1: err(1, "fork() failed"); case 0: - install = which(mypath); /* find system install avoiding mypath! */ + /* find system install avoiding mypath and portage_helper_path! */ + install = which(mypath, portage_helper_path); free(mypath); argv[0] = install; /* so coreutils' lib/program.c behaves */ execv(install, argv); /* The kernel will free(install). */