From patchwork Wed May 29 09:41:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Ziegler X-Patchwork-Id: 247210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id CA6202C00AA for ; Wed, 29 May 2013 19:41:44 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id CDB688C690; Wed, 29 May 2013 09:41:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m+Bnac-piYkw; Wed, 29 May 2013 09:41:34 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id D8FAF8C60E; Wed, 29 May 2013 09:41:32 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 14B6C8F76F for ; Wed, 29 May 2013 09:41:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3032C8C465 for ; Wed, 29 May 2013 09:41:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id maxB-pM1iScl for ; Wed, 29 May 2013 09:41:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mxz.fh-kl.de (mxz.fh-kl.de [143.93.17.66]) by whitealder.osuosl.org (Postfix) with ESMTP id 36D6E8C690 for ; Wed, 29 May 2013 09:41:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mxz.fh-kl.de (Postfix) with ESMTP id 38CECC80613 for ; Wed, 29 May 2013 11:41:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at fh-kl.de Received: from mxz.fh-kl.de ([127.0.0.1]) by localhost (mxz.fh-kl.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rc-NEFsLpt7y for ; Wed, 29 May 2013 11:41:19 +0200 (CEST) Received: from mail01.ds.fh-kl.de (mail01.fh-kl.de [143.93.17.114]) by mxz.fh-kl.de (Postfix) with ESMTPS for ; Wed, 29 May 2013 11:41:19 +0200 (CEST) Received: from [10.0.23.197] (143.93.17.33) by zwo222-ca01.ds.fh-kl.de (10.0.3.200) with Microsoft SMTP Server (TLS) id 14.2.342.3; Wed, 29 May 2013 11:41:19 +0200 Message-ID: <51A5CD3F.1070100@fh-kl.de> Date: Wed, 29 May 2013 11:41:19 +0200 From: Patrick Ziegler User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: X-Enigmail-Version: 1.5.1 X-Originating-IP: [143.93.17.33] Subject: [Buildroot] [PATCH] ext-toolchain-wrapper: fix paths if executable was resolved by PATH X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net If ext-toolchain-wrapper or any symbolic link to it was resolved by PATH, the wrapper takes the working directory to calculate the relative paths. Now '/proc/self/exe' is used to resolve the absolute path to the toolchain directory if the wrapper was called neither with a relative nor an absolute path. Signed-off-by: Patrick Ziegler Tested-by: Thomas Petazzoni --- toolchain/toolchain-external/ext-toolchain-wrapper.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c index 9a2fc70..e71a90a 100644 --- a/toolchain/toolchain-external/ext-toolchain-wrapper.c +++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c @@ -61,7 +61,7 @@ int main(int argc, char **argv) char *relbasedir, *absbasedir; char *progpath = argv[0]; char *basename; - int ret; + int ret, i, count = 0; /* Calculate the relative paths */ basename = strrchr(progpath, '/'); @@ -77,7 +77,19 @@ int main(int argc, char **argv) absbasedir = realpath(relbasedir, NULL); } else { basename = progpath; - absbasedir = realpath("../..", NULL); + absbasedir = malloc(PATH_MAX + 1); + ret = readlink("/proc/self/exe", absbasedir, PATH_MAX); + if (ret < 0) { + perror(__FILE__ ": readlink"); + return 2; + } + for (i = ret; i > 0; i--) { + if ('/' == absbasedir[i]) { + absbasedir[i] = '\0'; + if (3 == ++count) + break; + } + } } if (absbasedir == NULL) { perror(__FILE__ ": realpath");