1 |
commit: 84ca9ab04c49503ff2ef4346c45da63597ac204a |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jun 10 01:44:33 2014 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jun 10 01:49:08 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=84ca9ab0 |
7 |
|
8 |
misc/install-xattr: /proc/self/exe for canonical path to self |
9 |
|
10 |
Evaluating realpath(argv[0], NULL) when argv[0] is in the $PATH just |
11 |
returns argv[0] and not the full canonical path. Using /proc/self/exe |
12 |
is more reliable. |
13 |
|
14 |
--- |
15 |
misc/install-xattr/install-xattr.c | 17 +++++++++-------- |
16 |
1 file changed, 9 insertions(+), 8 deletions(-) |
17 |
|
18 |
diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c |
19 |
index 7dc248b..7b73cc3 100644 |
20 |
--- a/misc/install-xattr/install-xattr.c |
21 |
+++ b/misc/install-xattr/install-xattr.c |
22 |
@@ -162,9 +162,8 @@ copyxattr(const char *source, const char *target) |
23 |
|
24 |
|
25 |
static char * |
26 |
-which(const char *myfile) |
27 |
+which(char *mypath) |
28 |
{ |
29 |
- char *mypath = realpath(myfile, NULL); /* argv[0]'s canonical path */ |
30 |
char *path, *env_path = getenv("PATH"); /* full $PATH string */ |
31 |
char *portage_bin_path = getenv("PORTAGE_BIN_PATH"); /* PORTAGE BIN $PATHs to skip */ |
32 |
|
33 |
@@ -206,7 +205,6 @@ which(const char *myfile) |
34 |
*/ |
35 |
if (stat(canpath, &s) == 0) |
36 |
if (S_ISREG(s.st_mode)) { |
37 |
- free(mypath); |
38 |
free(path); |
39 |
return canpath; |
40 |
} |
41 |
@@ -238,11 +236,13 @@ main(int argc, char* argv[]) |
42 |
int first, last; /* argv indices of the first file/directory and last */ |
43 |
char *target; /* the target file or directory */ |
44 |
char *path; /* path to the target file */ |
45 |
- char *install; /* path to the system install */ |
46 |
+ |
47 |
+ char *mypath = realpath("/proc/self/exe", NULL); /* path to argv[0] */ |
48 |
+ char *install; /* path to the system install */ |
49 |
|
50 |
struct stat s; /* test if a file is a regular file or a directory */ |
51 |
|
52 |
- char *portage_xattr_exclude; /* strings of excluded xattr names from $PORTAGE_XATTR_EXCLUDE */ |
53 |
+ char *portage_xattr_exclude; /* strings of excluded xattr names from $PORTAGE_XATTR_EXCLUDE */ |
54 |
|
55 |
portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE"); |
56 |
if (portage_xattr_exclude == NULL) |
57 |
@@ -316,9 +316,10 @@ main(int argc, char* argv[]) |
58 |
err(1, "fork() failed"); |
59 |
|
60 |
case 0: |
61 |
- install = which(argv[0]); |
62 |
- argv[0] = install; /* so coreutils' lib/program.c behaves */ |
63 |
- execv(install, argv); /* The kernel will free(install). */ |
64 |
+ install = which(mypath); /* find system install avoiding mypath! */ |
65 |
+ free(mypath); |
66 |
+ argv[0] = install; /* so coreutils' lib/program.c behaves */ |
67 |
+ execv(install, argv); /* The kernel will free(install). */ |
68 |
err(1, "execv() failed"); |
69 |
|
70 |
default: |