From: Patrick Ziegler <patrick.ziegler@fh-kl.de>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] ext-toolchain-wrapper: fix paths if executable was resolved by PATH
Date: Wed, 29 May 2013 11:41:19 +0200 [thread overview]
Message-ID: <51A5CD3F.1070100@fh-kl.de> (raw)
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 <patrick.ziegler@fh-kl.de>
---
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");
--
1.8.1.2
--
Dipl.-Inf. (FH) Patrick Ziegler
University Of Applied Sciences
Kaiserslautern
Amerikastrasse 1
D-66482 Zweibruecken
Germany
Phone: +49 631 3724 5526
Mail: patrick.ziegler at fh-kl.de
PGP KeyID 0xB4796B8C
http://www.fh-kl.de
http://www.fh-kl.de/fachbereiche/imst/iuk-knowhow.html
next reply other threads:[~2013-05-29 9:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-29 9:41 Patrick Ziegler [this message]
2013-05-30 9:47 ` [Buildroot] [PATCH] ext-toolchain-wrapper: fix paths if executable was resolved by PATH Lionel Orry
2013-05-31 15:25 ` Thomas Petazzoni
2013-05-31 20:05 ` Peter Korsgaard
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=51A5CD3F.1070100@fh-kl.de \
--to=patrick.ziegler@fh-kl.de \
--cc=buildroot@busybox.net \
/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