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 9C83A1387FD for ; Tue, 10 Jun 2014 21:04:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 351E9E0A60; Tue, 10 Jun 2014 21:04:31 +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 B6D7DE0A60 for ; Tue, 10 Jun 2014 21:04:30 +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 BD3F233FFA3 for ; Tue, 10 Jun 2014 21:04:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 724A6181A9 for ; Tue, 10 Jun 2014 21:04:28 +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: <1402434139.522ab491f4e677baaa508cd43603861f7b0108fe.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: 522ab491f4e677baaa508cd43603861f7b0108fe X-VCS-Branch: master Date: Tue, 10 Jun 2014 21:04:28 +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: 17745a03-c60f-4515-b4f4-e44bee0d44c2 X-Archives-Hash: 19c2149656f6b42d80525a5bcd608ab6 commit: 522ab491f4e677baaa508cd43603861f7b0108fe Author: Anthony G. Basile gentoo org> AuthorDate: Tue Jun 10 21:02:19 2014 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Tue Jun 10 21:02:19 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=522ab491 misc/install-xattr: skip portage's install when searching for system install --- misc/install-xattr/install-xattr.c | 39 ++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c index 7b73cc3..4a165d0 100644 --- a/misc/install-xattr/install-xattr.c +++ b/misc/install-xattr/install-xattr.c @@ -164,8 +164,8 @@ copyxattr(const char *source, const char *target) static char * which(char *mypath) { - char *path, *env_path = getenv("PATH"); /* full $PATH string */ - char *portage_bin_path = getenv("PORTAGE_BIN_PATH"); /* PORTAGE BIN $PATHs to skip */ + char *path, *env_path = getenv("PATH"); /* $PATH to search for system install */ + char *portpath, *portage_bin_path = getenv("PORTAGE_BIN_PATH"); /* We skip $PORTAGE_BIN_PATH/install */ /* If we don't have $PATH in our environment, then pick a sane path. */ if (env_path == NULL) { @@ -175,14 +175,32 @@ which(char *mypath) } else path = xstrdup(env_path); + /* If we have a $PORTAGE_BIN_PATH, then assume portage's install is at + * $PORTAGE_BIN_PATH/install. See 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) + portpath = NULL; + else { + struct stat s; + + portpath = path_join(portage_bin_path, "install"); + portpath = realpath(portpath, NULL); + + if (stat(portpath, &s) != 0) /* If the path doesn't exsist, then portpath = NULL */ + portpath = NULL; + else + if (!S_ISREG(s.st_mode)) /* If it exists and isn't a file/sym link, portpath = NULL */ + 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 *sdir; /* one directory in the $INSTALL_EXCLUDE_PATH string */ char *savedptr; /* reentrant context for strtok_r() */ - struct stat s; - dir = strtok_r(path, ":", &savedptr); while (dir) { @@ -194,18 +212,27 @@ which(char *mypath) if (!canpath) goto skip; - /* If argv[0]'s canonical path == candidates install's canonical path, + /* If argv[0]'s canonical path == candidate install's canonical path, * then we skip this path otheriwise we get into an infinite self-invocation. */ if (!strcmp(mypath, canpath)) goto skip; + /* 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 (!strcmp(portpath, canpath)) + goto skip; + /* If the canpath exists and is either a regular file or sym link, * assume we found the system's install. */ + struct stat s; + if (stat(canpath, &s) == 0) if (S_ISREG(s.st_mode)) { free(path); + free(portpath); return canpath; }