perf tools: Ensure --symfs ends with '/'
Namhyung Kim
maintainerPATCH 1/2 perf tools: Ensure --symfs ends with '/'
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
--- tools/perf/util/symbol.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
tools/perf/util/symbol.c +29 -12
@@ -1829,7 +1829,7 @@ static bool symbol__read_kptr_restrict(void)int symbol__init (void ) { -const char *symfs; +char *symfs;if (symbol_conf.initialized)return 0 ;
@@ -1862,23 +1862,40 @@ int symbol__init(void) symbol_conf.sym_list_str, "symbol") < 0) goto out_free_comm_list; -/* -* A path to symbols of "/" is identical to "" -* reset here for simplicity. -*/ - symfs =realpath (symbol_conf.symfs,NULL ); -if (symfs ==NULL ) - symfs = symbol_conf.symfs; -if (strcmp (symfs,"/" ) ==0 ) - symbol_conf.symfs ="" ; -if (symfs != symbol_conf.symfs) -free ((void *)symfs); +if (*symbol_conf.symfs) { + symfs =realpath (symbol_conf.symfs,NULL ); +if (symfs ==NULL ) + symfs = (char *)symbol_conf.symfs; + +/* +* A path to symbols of "/" is identical to "" +* reset here for simplicity. +*/ +if (strcmp (symfs,"/" ) ==0 ) + symbol_conf.symfs ="" ; + +/* ensure symfs ends with '/' */ +if (symfs[strlen (symfs)-1 ] !='/' ) { +char *tmp =realloc (symfs,strlen (symfs) +2 ); +if (tmp ==NULL ) + goto out_free; + + tmp[strlen (tmp)+1 ] ='\0' ; + tmp[strlen (tmp)] ='/' ; + + symbol_conf.symfs = tmp; + }else { +free (symfs); + } + } symbol_conf.kptr_restrict =symbol__read_kptr_restrict (); symbol_conf.initialized = true;return 0 ; +out_free: +free (symfs); out_free_comm_list:strlist__delete (symbol_conf.comm_list); out_free_dso_list:
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 2/2 perf tools: Check validity of --symfs value
If a symfs is given by user, it needs to be checked before applying. Currently, it just uses it even if realpath() failed.
I guess it's because it needed to handle empty symfs which is the default value. But now it's only called when it's not empty so it'd be better to check before using it and warn users if failed.
--- tools/perf/util/symbol.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +5 -2
@@ -1864,8 +1864,11 @@ int symbol__init(void)if (*symbol_conf.symfs) { symfs =realpath (symbol_conf.symfs,NULL ); -if (symfs ==NULL ) - symfs = (char *)symbol_conf.symfs; +if (symfs ==NULL ) { +pr_err ("cannot apply symfs: %s: %s\n" , + symbol_conf.symfs,strerror (errno)); +return -1 ; + }/* * A path to symbols of "/" is identical to ""
Signature · 1 line
2.0.0
Arnaldo Carvalho de Melo
maintainerEm Fri, Jul 25, 2014 at 10:31:47AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
I don't think this is the right way of doing this, users of symbol_conf.symfs should instead make sure that they do what they expect to, i.e. if they want it to be a base directory, make sure that a path separator is added between it and the relative path following it, if not, do as they please.
- Arnaldo
Quoted 73 lines
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/symbol.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)tools/perf/util/symbol.c +29
-12@@ -1829,7 +1829,7 @@ static bool symbol__read_kptr_restrict(void)int symbol__init (void ) { -const char *symfs; +char *symfs;if (symbol_conf.initialized)return 0 ;@@ -1862,23 +1862,40 @@ int symbol__init(void) symbol_conf.sym_list_str, "symbol") < 0) goto out_free_comm_list; -/* -* A path to symbols of "/" is identical to "" -* reset here for simplicity. -*/ - symfs =realpath (symbol_conf.symfs,NULL ); -if (symfs ==NULL ) - symfs = symbol_conf.symfs; -if (strcmp (symfs,"/" ) ==0 ) - symbol_conf.symfs ="" ; -if (symfs != symbol_conf.symfs) -free ((void *)symfs); +if (*symbol_conf.symfs) { + symfs =realpath (symbol_conf.symfs,NULL ); +if (symfs ==NULL ) + symfs = (char *)symbol_conf.symfs; + +/* +* A path to symbols of "/" is identical to "" +* reset here for simplicity. +*/ +if (strcmp (symfs,"/" ) ==0 ) + symbol_conf.symfs ="" ; + +/* ensure symfs ends with '/' */ +if (symfs[strlen (symfs)-1 ] !='/' ) { +char *tmp =realloc (symfs,strlen (symfs) +2 ); +if (tmp ==NULL ) + goto out_free; + + tmp[strlen (tmp)+1 ] ='\0' ; + tmp[strlen (tmp)] ='/' ; + + symbol_conf.symfs = tmp; + }else { +free (symfs); + } + } symbol_conf.kptr_restrict =symbol__read_kptr_restrict (); symbol_conf.initialized = true;return 0 ; +out_free: +free (symfs); out_free_comm_list:strlist__delete (symbol_conf.comm_list); out_free_dso_list:Signature · 1 line
2.0.0
Namhyung Kim
maintainerHi Arnaldo,
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Fri, Jul 25, 2014 at 10:31:47AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
I don't think this is the right way of doing this, users of symbol_conf.symfs should instead make sure that they do what they expect to, i.e. if they want it to be a base directory, make sure that a path separator is added between it and the relative path following it, if not, do as they please.
Hmm.. what's the usecase of non-directory symfs? I guess realpath(3) already nullifies such case and defaults to no symfs..
Thanks,
Namhyung
Quoted 6 lines · Namhyung Kim
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Both patches work and are handy to me.
Thanks Namhyung.
Signature · 2 lines
Kind regards, Minchan Kim
Arnaldo Carvalho de Melo
maintainerEm Tue, Jul 29, 2014 at 02:02:46PM +0900, Minchan Kim escreveu:
Quoted 10 lines · Namhyung Kim
Quoted 6 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Both patches work and are handy to me.
Thanks Namhyung.
I haven't said it is not :-) Just that it should be fixed in a different way.
Can you please try the patch below instead?
David, was there any reason not to do it like done in this patch?
- Arnaldo
--- annotate.c | 4 ++-- dso.c | 8 ++++---- symbol.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
tools/perf/util/annotate.c +2 -2
@@ -900,7 +900,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)bool delete_extract = false;if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); }
@@ -922,7 +922,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); free_filename = false; }
tools/perf/util/dso.c +4 -4
@@ -79,7 +79,7 @@ int dso__read_binary_type_filename(const struct dso *dso,while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =scnprintf (filename, size,"%s/" , symbol_conf.symfs); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;
@@ -108,17 +108,17 @@ int dso__read_binary_type_filename(const struct dso *dso,case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s/%s" , symbol_conf.symfs, root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;
tools/perf/util/symbol.c +1 -1
@@ -1468,7 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , +snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s/%s" , symbol_conf.symfs, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL )
Hello,
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 29, 2014 at 02:02:46PM +0900, Minchan Kim escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Both patches work and are handy to me.
Thanks Namhyung.I haven't said it is not :-) Just that it should be fixed in a different way.
I just wanted to confirm Namhyung's patches work as reporter. :)
Quoted 2 lines
Can you please try the patch below instead?
Tested. It works.
And I'd like to say that [2/2] in patchset is handy to me.
Thanks.
Quoted 80 lines
David, was there any reason not to do it like done in this patch?
- Arnaldo
--- annotate.c | 4 ++-- dso.c | 8 ++++---- symbol.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)tools/perf/util/annotate.c +2
-2@@ -900,7 +900,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)bool delete_extract = false;if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); }@@ -922,7 +922,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); free_filename = false; }tools/perf/util/dso.c +4
-4@@ -79,7 +79,7 @@ int dso__read_binary_type_filename(const struct dso *dso,while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =scnprintf (filename, size,"%s/" , symbol_conf.symfs); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;@@ -108,17 +108,17 @@ int dso__read_binary_type_filename(const struct dso *dso,case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s/%s" , symbol_conf.symfs, root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;tools/perf/util/symbol.c +1
-1@@ -1468,7 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , +snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s/%s" , symbol_conf.symfs, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL )
Signature · 2 lines
Kind regards, Minchan Kim
Arnaldo Carvalho de Melo
maintainerEm Tue, Jul 29, 2014 at 10:26:57PM +0900, Minchan Kim escreveu:
Quoted 18 lines
Hello,
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 29, 2014 at 02:02:46PM +0900, Minchan Kim escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Both patches work and are handy to me.
Thanks Namhyung.I haven't said it is not :-) Just that it should be fixed in a different way.
Quoted 6 lines
I just wanted to confirm Namhyung's patches work as reporter. :)
Quoted 2 lines
Can you please try the patch below instead?
Tested. It works.
Thanks, Adding a Tested-by: you, in addition to the Reported-by: you already there.
Quoted 1 line
And I'd like to say that [2/2] in patchset is handy to me.
I'll check it.
Quoted 86 lines
Thanks.
Quoted 80 lines
David, was there any reason not to do it like done in this patch?
- Arnaldo
--- annotate.c | 4 ++-- dso.c | 8 ++++---- symbol.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)tools/perf/util/annotate.c +2
-2@@ -900,7 +900,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)bool delete_extract = false;if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); }@@ -922,7 +922,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); free_filename = false; }tools/perf/util/dso.c +4
-4@@ -79,7 +79,7 @@ int dso__read_binary_type_filename(const struct dso *dso,while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =scnprintf (filename, size,"%s/" , symbol_conf.symfs); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;@@ -108,17 +108,17 @@ int dso__read_binary_type_filename(const struct dso *dso,case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s/%s" , symbol_conf.symfs, root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;tools/perf/util/symbol.c +1
-1@@ -1468,7 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , +snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s/%s" , symbol_conf.symfs, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL )Signature · 2 lines
Kind regards, Minchan Kim
Arnaldo Carvalho de Melo
maintainerEm Tue, Jul 29, 2014 at 10:26:57PM +0900, Minchan Kim escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 1 line
Can you please try the patch below instead?
Tested. It works.
And I'd like to say that [2/2] in patchset is handy to me.
Ok, here it is, refreshed, will apply with Namhyung as author as the change should be functionally equivalent to what he did.
Please check that it works as expected,
Thanks,
- Arnaldo
---
tools/perf/util/symbol.c +11 -3
@@ -1862,13 +1862,21 @@ int symbol__init(void) symbol_conf.sym_list_str, "symbol") < 0) goto out_free_comm_list; +if (symbol_conf.symfs[0 ] !='\0' ) { + symfs =realpath (symbol_conf.symfs,NULL ); +if (symfs ==NULL ) { +pr_debug ("Cannot apply symfs: %s: %s\n" , + symbol_conf.symfs,strerror (errno)); +return -1 ; + } + }else { + symfs = symbol_conf.symfs; + } +/* * A path to symbols of "/" is identical to "" * reset here for simplicity. */ - symfs =realpath (symbol_conf.symfs,NULL ); -if (symfs ==NULL ) - symfs = symbol_conf.symfs;if (strcmp (symfs,"/" ) ==0 ) symbol_conf.symfs ="" ;if (symfs != symbol_conf.symfs)
Quoted 2 lines · Arnaldo Carvalho de Melo
David, was there any reason not to do it like done in this patch?
I feel like we did at one point.
<searching>
http://www.spinics.net/lists/linux-perf-users/msg00252.html
So my original rootfs patch did use '/' after the path.
Incarnation as symfs which got accepted:
https://lkml.org/lkml/2010/12/9/391
has it removed.
I recall you running the patch through a number of scenarios. I do not recall the reason '/' got dropped.
David
Namhyung Kim
maintainerHi Arnaldo,
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 29, 2014 at 02:02:46PM +0900, Minchan Kim escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Reported-by Minchan Kim <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Both patches work and are handy to me.
Thanks Namhyung.I haven't said it is not :-) Just that it should be fixed in a different way.
I also thought about that way first but changed my mind to the current approach because I don't want to change current behavior.
I worried about the common case which has empty symfs. By your patch, it makes a pathname absolute even with an empty symfs - I can see most filenames are already absolute paths but I'm not 100% sure it's always the case.
Thanks,
Namhyung
Quoted 82 lines
Can you please try the patch below instead?
David, was there any reason not to do it like done in this patch?
- Arnaldo
--- annotate.c | 4 ++-- dso.c | 8 ++++---- symbol.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)tools/perf/util/annotate.c +2
-2@@ -900,7 +900,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)bool delete_extract = false;if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); }@@ -922,7 +922,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , +snprintf (symfs_filename,sizeof (symfs_filename),"%s/%s" , symbol_conf.symfs, filename); free_filename = false; }tools/perf/util/dso.c +4
-4@@ -79,7 +79,7 @@ int dso__read_binary_type_filename(const struct dso *dso,while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =scnprintf (filename, size,"%s/" , symbol_conf.symfs); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;@@ -108,17 +108,17 @@ int dso__read_binary_type_filename(const struct dso *dso,case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s/%s" , symbol_conf.symfs, root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, +snprintf (filename, size,"%s/%s" , symbol_conf.symfs, dso->long_name);break ;tools/perf/util/symbol.c +1
-1@@ -1468,7 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , +snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s/%s" , symbol_conf.symfs, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL )
Arnaldo Carvalho de Melo
maintainerEm Wed, Jul 30, 2014 at 08:52:36AM +0900, Namhyung Kim escreveu:
Quoted 15 lines
Hi Arnaldo,
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 29, 2014 at 02:02:46PM +0900, Minchan Kim escreveu:
Quoted 7 lines · Namhyung Kim
Quoted 3 lines
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character. So make sure that the symfs always ends with the '/'.
Both patches work and are handy to me.
Thanks Namhyung.I haven't said it is not :-) Just that it should be fixed in a different way.
Quoted 7 lines
I also thought about that way first but changed my mind to the current approach because I don't want to change current behavior.
I worried about the common case which has empty symfs. By your patch, it makes a pathname absolute even with an empty symfs - I can see most filenames are already absolute paths but I'm not 100% sure it's always the case.
Yeah, after doing some research on the tools/perf/ 'git log' I got your point, we can't add the / after symfs usages when it is "", i.e. we need something like:
("%s%s%s, symfs, symfs[0] ? "/" : "", dso_name)I.e. the equivalent of this:
[acme@zoo linux]$ python
Python 2.7.5 (default, Jun 25 2014, 10:19:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import os
symfs = ""os.path.join(symfs, "dso_path")
'dso_path'
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
symfs = "
/home/acme/embedded_device_dsos"os.path.join(symfs, "dso_path")
'/home/acme/embedded_device_dsos/dso_path'
Quoted 1 line
Quoted 1 line
Quoted 1 line
I'll try and get that in place.
- Arnaldo
Em Wed, Jul 30, 2014 at 12:19:32PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Jul 30, 2014 at 08:52:36AM +0900, Namhyung Kim escreveu:
Quoted 7 lines
I also thought about that way first but changed my mind to the current approach because I don't want to change current behavior.
I worried about the common case which has empty symfs. By your patch, it makes a pathname absolute even with an empty symfs - I can see most filenames are already absolute paths but I'm not 100% sure it's always the case.
Yeah, after doing some research on the
tools/perf/'git log' I got your point, we can't add the / after symfs usages when it is "", i.e. we need something like:("%s%s%s, symfs, symfs[0] ? "/" : "", dso_name)I.e. the equivalent of this:
[acme@zoo linux]$ python
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import os
symfs = ""os.path.join(symfs, "dso_path")
Quoted 7 lines
'
dso_path'Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
symfs = "
/home/acme/embedded_device_dsos"os.path.join(symfs, "dso_path")'
/home/acme/embedded_device_dsos/dso_path'Quoted 1 line
Quoted 1 line
Quoted 1 line
I'll try and get that in place.
Ok, the patch below should implement it just like above, if Minchan could please retest, I did just minimal testing, will do more later.
- Arnaldo
---
Quoted 1 line
From
d0240769e7d844ee21c1e8fc5cc57627c666f155Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Tue, 29 Jul 2014 10:21:58 -0300
Subject: [PATCH 1/1] perf symbols: Make sure --symfs usage includes the path
separator
Minchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character.
Fix it by making sure that the '/' path separator is used when composing pathnames with a --symfs provided directory name.
--- tools/perf/util/annotate.c | 9 +++------ tools/perf/util/dso.c | 28 +++++++++++++--------------- tools/perf/util/symbol.c | 3 +-- tools/perf/util/symbol.h | 9 +++++++++ tools/perf/util/util.h | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 23 deletions(-)
tools/perf/util/annotate.c +3 -6
@@ -899,10 +899,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)struct kcore_extract kce;bool delete_extract = false; -if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , - symbol_conf.symfs, filename); - } +if (filename) +symbol__join_symfs (symfs_filename, filename);if (filename ==NULL ) {if (dso->has_build_id) {
@@ -922,8 +920,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , - symbol_conf.symfs, filename); +symbol__join_symfs (symfs_filename, filename); free_filename = false; }
tools/perf/util/dso.c +13 -15
@@ -37,6 +37,7 @@ int dso__read_binary_type_filename(const struct dso *dso, {char build_id_hex[BUILD_ID_SIZE *2 +1 ];int ret =0 ; +size_t len;switch (type) {case DSO_BINARY_TYPE__DEBUGLINK : {
@@ -60,26 +61,25 @@ int dso__read_binary_type_filename(const struct dso *dso,break ;case DSO_BINARY_TYPE__FEDORA_DEBUGINFO : -snprintf (filename, size,"%s/usr/lib/debug%s.debug" , - symbol_conf.symfs, dso->long_name); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug" ); +snprintf (filename + len, size - len,"%s.debug" , dso->long_name);break ;case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO : -snprintf (filename, size,"%s/usr/lib/debug%s" , - symbol_conf.symfs, dso->long_name); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug" ); +snprintf (filename + len, size - len,"%s" , dso->long_name);break ;case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO : {const char *last_slash; -size_t len;size_t dir_size; last_slash = dso->long_name + dso->long_name_len;while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =__symbol__join_symfs (filename, size,"" ); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;
@@ -100,26 +100,24 @@ int dso__read_binary_type_filename(const struct dso *dso,build_id__sprintf (dso->build_id,sizeof (dso->build_id), build_id_hex); -snprintf (filename, size, -"%s/usr/lib/debug/.build-id/%.2s/%s.debug" , - symbol_conf.symfs, build_id_hex, build_id_hex +2 ); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug/.build-id/" ); +snprintf (filename + len, size - len,"%.2s/%s.debug" , + build_id_hex, build_id_hex +2 );break ;case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , - symbol_conf.symfs, dso->long_name); +__symbol__join_symfs (filename, size, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, - root_dir, dso->long_name); +path__join3 (filename, size, symbol_conf.symfs, + root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, - dso->long_name); +__symbol__join_symfs (filename, size, dso->long_name);break ;case DSO_BINARY_TYPE__KCORE :
tools/perf/util/symbol.c +1 -2
@@ -1468,8 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , - symbol_conf.symfs, vmlinux); +symbol__join_symfs (symfs_vmlinux, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL ) symtab_type =DSO_BINARY_TYPE__GUEST_VMLINUX ;
tools/perf/util/symbol.h +9 -0
@@ -13,6 +13,7 @@#include <libgen.h> #include "build-id.h" #include "event.h" +#include "util.h" #ifdef HAVE_LIBELF_SUPPORT #include <libelf.h>
@@ -143,6 +144,14 @@ struct symbol_conf { };extern struct symbol_conf symbol_conf; + +static inline int __symbol__join_symfs (char *bf,size_t size,const char *path) +{ +return path__join (bf, size, symbol_conf.symfs, path); +} + +#define symbol__join_symfs (bf, path) __symbol__join_symfs(bf, sizeof(bf), path) +extern int vmlinux_path__nr_entries;extern char **vmlinux_path;
tools/perf/util/util.h +16 -0
@@ -68,6 +68,7 @@#include <sys/socket.h> #include <sys/ioctl.h> #include <inttypes.h> +#include <linux/kernel.h> #include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h>
@@ -317,6 +318,21 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags);#define SRCLINE_UNKNOWN ((char *) "??:0") +static inline int path__join (char *bf,size_t size, +const char *path1,const char *path2) +{ +return scnprintf (bf, size,"%s%s%s" , path1, path1[0 ] ?"/" :"" , path2); +} + +static inline int path__join3 (char *bf,size_t size, +const char *path1,const char *path2, +const char *path3) +{ +return scnprintf (bf, size,"%s%s%s%s%s" , + path1, path1[0 ] ?"/" :"" , + path2, path2[0 ] ?"/" :"" , path3); +} +struct dso ;char *get_srcline (struct dso *dso,unsigned long addr);
Signature · 1 line
1.8.5.rc2
Quoted 5 lines · Arnaldo Carvalho de Melo
tools/perf/util/symbol.h +1
-0@@ -143,6 +144,14 @@ struct symbol_conf { };extern struct symbol_conf symbol_conf; +
tools/perf/util/symbol.h struct symbol_conf { · line 157
Quoted 10 lines
tools/perf/util/symbol.h +7
-0+static inline int __symbol__join_symfs (char *bf,size_t size,const char *path) +{ +return path__join (bf, size, symbol_conf.symfs, path); +} + +#define symbol__join_symfs (bf, path) __symbol__join_symfs(bf, sizeof(bf), path) +extern int vmlinux_path__nr_entries;extern char **vmlinux_path;
I am not comfortable with the sizeof(bf) in the macro there. It is to a large degree hiding an important detail and sets up odd failures in the future. ie., It works fine for 'char bf[N];' but not for 'char *bf = "some string";'.
David
Namhyung Kim
maintainerHi Arnaldo,
Quoted 25 lines · Arnaldo Carvalho de Melo
Em Wed, Jul 30, 2014 at 12:19:32PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 24 lines
Em Wed, Jul 30, 2014 at 08:52:36AM +0900, Namhyung Kim escreveu:
Quoted 7 lines
I also thought about that way first but changed my mind to the current approach because I don't want to change current behavior.
I worried about the common case which has empty symfs. By your patch, it makes a pathname absolute even with an empty symfs - I can see most filenames are already absolute paths but I'm not 100% sure it's always the case.
Yeah, after doing some research on the
tools/perf/'git log' I got your point, we can't add the / after symfs usages when it is "", i.e. we need something like:("%s%s%s, symfs, symfs[0] ? "/" : "", dso_name)I.e. the equivalent of this:
[acme@zoo linux]$ python
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import os
symfs = ""os.path.join(symfs, "dso_path")'
dso_path'Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
symfs = "
/home/acme/embedded_device_dsos"os.path.join(symfs, "dso_path")
Quoted 7 lines
Quoted 4 lines
'
/home/acme/embedded_device_dsos/dso_path'Quoted 1 line
Quoted 1 line
Quoted 1 line
I'll try and get that in place.
Ok, the patch below should implement it just like above, if Minchan could please retest, I did just minimal testing, will do more later.
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Thanks,
Namhyung
Quoted 215 lines
- Arnaldo
---
From
d0240769e7d844ee21c1e8fc5cc57627c666f155Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Tue, 29 Jul 2014 10:21:58 -0300
Subject: [PATCH 1/1] perf symbols: Make sure --symfs usage includes the path
separatorMinchan reported that perf failed to load vmlinux if --symfs argument doesn't end with '/' character.
Fix it by making sure that the '/' path separator is used when composing pathnames with a --symfs provided directory name.
Reported-by Minchan Kim <[email protected]>Tested-by Minchan Kim <[email protected]>Cc David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Minchan Kim <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/annotate.c | 9 +++------ tools/perf/util/dso.c | 28 +++++++++++++--------------- tools/perf/util/symbol.c | 3 +-- tools/perf/util/symbol.h | 9 +++++++++ tools/perf/util/util.h | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 23 deletions(-)tools/perf/util/annotate.c +3
-6@@ -899,10 +899,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)struct kcore_extract kce;bool delete_extract = false; -if (filename) { -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , - symbol_conf.symfs, filename); - } +if (filename) +symbol__join_symfs (symfs_filename, filename);if (filename ==NULL ) {if (dso->has_build_id) {@@ -922,8 +920,7 @@ fallback:* DSO is the same as when 'perf record' ran. */ filename = (char *)dso->long_name; -snprintf (symfs_filename,sizeof (symfs_filename),"%s%s" , - symbol_conf.symfs, filename); +symbol__join_symfs (symfs_filename, filename); free_filename = false; }tools/perf/util/dso.c +13
-15@@ -37,6 +37,7 @@ int dso__read_binary_type_filename(const struct dso *dso, {char build_id_hex[BUILD_ID_SIZE *2 +1 ];int ret =0 ; +size_t len;switch (type) {case DSO_BINARY_TYPE__DEBUGLINK : {@@ -60,26 +61,25 @@ int dso__read_binary_type_filename(const struct dso *dso,break ;case DSO_BINARY_TYPE__FEDORA_DEBUGINFO : -snprintf (filename, size,"%s/usr/lib/debug%s.debug" , - symbol_conf.symfs, dso->long_name); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug" ); +snprintf (filename + len, size - len,"%s.debug" , dso->long_name);break ;case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO : -snprintf (filename, size,"%s/usr/lib/debug%s" , - symbol_conf.symfs, dso->long_name); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug" ); +snprintf (filename + len, size - len,"%s" , dso->long_name);break ;case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO : {const char *last_slash; -size_t len;size_t dir_size; last_slash = dso->long_name + dso->long_name_len;while (last_slash != dso->long_name && *last_slash !='/' ) last_slash--; - len =scnprintf (filename, size,"%s" , symbol_conf.symfs); + len =__symbol__join_symfs (filename, size,"" ); dir_size = last_slash - dso->long_name +2 ;if (dir_size > (size - len)) { ret =-1 ;@@ -100,26 +100,24 @@ int dso__read_binary_type_filename(const struct dso *dso,build_id__sprintf (dso->build_id,sizeof (dso->build_id), build_id_hex); -snprintf (filename, size, -"%s/usr/lib/debug/.build-id/%.2s/%s.debug" , - symbol_conf.symfs, build_id_hex, build_id_hex +2 ); + len =__symbol__join_symfs (filename, size,"/usr/lib/debug/.build-id/" ); +snprintf (filename + len, size - len,"%.2s/%s.debug" , + build_id_hex, build_id_hex +2 );break ;case DSO_BINARY_TYPE__VMLINUX :case DSO_BINARY_TYPE__GUEST_VMLINUX :case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : -snprintf (filename, size,"%s%s" , - symbol_conf.symfs, dso->long_name); +__symbol__join_symfs (filename, size, dso->long_name);break ;case DSO_BINARY_TYPE__GUEST_KMODULE : -snprintf (filename, size,"%s%s%s" , symbol_conf.symfs, - root_dir, dso->long_name); +path__join3 (filename, size, symbol_conf.symfs, + root_dir, dso->long_name);break ;case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : -snprintf (filename, size,"%s%s" , symbol_conf.symfs, - dso->long_name); +__symbol__join_symfs (filename, size, dso->long_name);break ;case DSO_BINARY_TYPE__KCORE :tools/perf/util/symbol.c +1
-2@@ -1468,8 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,if (vmlinux[0 ] =='/' )snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s" , vmlinux);else -snprintf (symfs_vmlinux,sizeof (symfs_vmlinux),"%s%s" , - symbol_conf.symfs, vmlinux); +symbol__join_symfs (symfs_vmlinux, vmlinux);if (dso->kernel ==DSO_TYPE_GUEST_KERNEL ) symtab_type =DSO_BINARY_TYPE__GUEST_VMLINUX ;tools/perf/util/symbol.h +9
-0@@ -13,6 +13,7 @@#include <libgen.h> #include "build-id.h" #include "event.h" +#include "util.h" #ifdef HAVE_LIBELF_SUPPORT #include <libelf.h> @@ -143,6 +144,14 @@ struct symbol_conf { };extern struct symbol_conf symbol_conf; + +static inline int __symbol__join_symfs (char *bf,size_t size,const char *path) +{ +return path__join (bf, size, symbol_conf.symfs, path); +} + +#define symbol__join_symfs (bf, path) __symbol__join_symfs(bf, sizeof(bf), path) +extern int vmlinux_path__nr_entries;extern char **vmlinux_path;tools/perf/util/util.h +16
-0@@ -68,6 +68,7 @@#include <sys/socket.h> #include <sys/ioctl.h> #include <inttypes.h> +#include <linux/kernel.h> #include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> @@ -317,6 +318,21 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags);#define SRCLINE_UNKNOWN ((char *) "??:0") +static inline int path__join (char *bf,size_t size, +const char *path1,const char *path2) +{ +return scnprintf (bf, size,"%s%s%s" , path1, path1[0 ] ?"/" :"" , path2); +} + +static inline int path__join3 (char *bf,size_t size, +const char *path1,const char *path2, +const char *path3) +{ +return scnprintf (bf, size,"%s%s%s%s%s" , + path1, path1[0 ] ?"/" :"" , + path2, path2[0 ] ?"/" :"" , path3); +} +struct dso ;char *get_srcline (struct dso *dso,unsigned long addr);
Arnaldo Carvalho de Melo
maintainerEm Thu, Jul 31, 2014 at 01:25:52PM +0900, Namhyung Kim escreveu:
Quoted 26 lines
Hi Arnaldo,
Quoted 22 lines · Arnaldo Carvalho de Melo
Em Wed, Jul 30, 2014 at 12:19:32PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Jul 30, 2014 at 08:52:36AM +0900, Namhyung Kim escreveu:
Quoted 7 lines
I also thought about that way first but changed my mind to the current approach because I don't want to change current behavior.
I worried about the common case which has empty symfs. By your patch, it makes a pathname absolute even with an empty symfs - I can see most filenames are already absolute paths but I'm not 100% sure it's always the case.
Yeah, after doing some research on the
tools/perf/'git log' I got your point, we can't add the / after symfs usages when it is "", i.e. we need something like:[acme@zoo linux]$ python
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import os
symfs = ""os.path.join(symfs, "dso_path")'
dso_path'Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
symfs = "
/home/acme/embedded_device_dsos"os.path.join(symfs, "dso_path")'
/home/acme/embedded_device_dsos/dso_path'
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I'll try and get that in place.
Ok, the patch below should implement it just like above, if Minchan could please retest, I did just minimal testing, will do more later.
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Yes, I am.
We are not just concatenating two strings, we are joining two path components.
I think it is more clear and elegant to do it as python os.path.join() does.
- Arnaldo
Namhyung Kim
maintainerHi Arnaldo,
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 31, 2014 at 01:25:52PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Yes, I am.
We are not just concatenating two strings, we are joining two path components.
I think it is more clear and elegant to do it as python
os.path.join()does.
Then I think you also need to care about trailing and leading '/' in the components so that, say, joining '/home/' and '/namhyung/' can result in '/home/namhyung/' not '/home///namhyung/'.
Btw, it seems like python's os.path.join() just use latter if it's an absolute path.
$ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import os.path
os.path.join('/home/', '/namhyung/')
'/namhyung/'
Quoted 1 line
Quoted 1 line
Quoted 1 line
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerEm Fri, Aug 01, 2014 at 08:38:02AM +0900, Namhyung Kim escreveu:
Quoted 12 lines
Hi Arnaldo,
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 31, 2014 at 01:25:52PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Yes, I am.
We are not just concatenating two strings, we are joining two path components.
Quoted 6 lines
Quoted 2 lines
I think it is more clear and elegant to do it as python
os.path.join()does.Then I think you also need to care about trailing and leading '/' in the components so that, say, joining '
/home/' and '/namhyung/' can result in '/home/namhyung/' not '/home///namhyung/'.
Well, "/home/namhyung/" is the same as "/home///namhyung/" for POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266
So, when we can easily avoid it, no use to have a sequence of slashes, but otherwise it is harmless.
Quoted 10 lines
Btw, it seems like python's
os.path.join()just use latter if it's an absolute path.$ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import os.path
os.path.join('/home/', '/namhyung/')'/namhyung/'
Interesting, wonder what is the rationale for that or if this is a bug.
- Arnaldo
Namhyung Kim
maintainerHi Arnaldo,
Quoted 20 lines · Arnaldo Carvalho de Melo
Em Fri, Aug 01, 2014 at 08:38:02AM +0900, Namhyung Kim escreveu:
Quoted 12 lines
Hi Arnaldo,
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 31, 2014 at 01:25:52PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Yes, I am.
We are not just concatenating two strings, we are joining two path components.
Quoted 6 lines
Quoted 2 lines
I think it is more clear and elegant to do it as python
os.path.join()does.Then I think you also need to care about trailing and leading '/' in the components so that, say, joining '
/home/' and '/namhyung/' can result in '/home/namhyung/' not '/home///namhyung/'.
Quoted 5 lines
Well, "
/home/namhyung/" is the same as "/home///namhyung/" for POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266So, when we can easily avoid it, no use to have a sequence of slashes, but otherwise it is harmless.
Yes, I know it's supported. But I think it'd be better off avoiding it in order to be an elegant path joiner. :)
Quoted 12 lines
Quoted 11 lines
Btw, it seems like python's
os.path.join()just use latter if it's an absolute path.$ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import os.path
os.path.join('/home/', '/namhyung/')'/namhyung/'
Quoted 1 line
Interesting, wonder what is the rationale for that or if this is a bug.
Hmm.. pydoc os.path.join says below:
os.path.join = join(a, *p)
Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerEm Mon, Aug 11, 2014 at 04:38:17PM +0900, Namhyung Kim escreveu:
Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 17 lines
Em Fri, Aug 01, 2014 at 08:38:02AM +0900, Namhyung Kim escreveu:
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 11 lines
Em Thu, Jul 31, 2014 at 01:25:52PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
Are you still against my approach - adding '/' at the end of the symfs string itself? It seems that mine is simpler and shorter.
Yes, I am.
We are not just concatenating two strings, we are joining two path components.
I think it is more clear and elegant to do it as python
os.path.join()does.Then I think you also need to care about trailing and leading '/' in the components so that, say, joining '
/home/' and '/namhyung/' can result in '/home/namhyung/' not '/home///namhyung/'.
Quoted 8 lines
Quoted 5 lines
Well, "
/home/namhyung/" is the same as "/home///namhyung/" for POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266So, when we can easily avoid it, no use to have a sequence of slashes, but otherwise it is harmless.
Yes, I know it's supported. But I think it'd be better off avoiding it in order to be an elegant path joiner. :)
Yeah, when we can do such things with just one or two lines of code, that is ok, but if not, hey, the kernel will do it for us. I.e. there _is_ code already to make it sane, to understand the intent. And it is _always_ in place, since this is a standard.
Quoted 13 lines
Quoted 11 lines
Quoted 10 lines
Btw, it seems like python's
os.path.join()just use latter if it's an absolute path.$ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import os.path
os.path.join('/home/', '/namhyung/')'/namhyung/'
Quoted 1 line
Interesting, wonder what is the rationale for that or if this is a bug.
Quoted 8 lines
Hmm.. pydoc os.path.join says below:
os.path.join =
join(a, *p)Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.
It states the behaviour, but doesn't present the rationale, that left me wondering :)
- Arnaldo