diff options
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> | 2013-06-21 21:27:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-06-27 03:44:46 +0200 |
commit | 879f008a8f890f83a005d0816d259c6157121e5b (patch) | |
tree | c04cb9e6376d8eb18e17d19eaa9f8e35ce45a86b | |
parent | d66eb9042dcc6ee274949fb83612cecbbde44a4a (diff) | |
download | busybox-w32-879f008a8f890f83a005d0816d259c6157121e5b.tar.gz busybox-w32-879f008a8f890f83a005d0816d259c6157121e5b.tar.bz2 busybox-w32-879f008a8f890f83a005d0816d259c6157121e5b.zip |
lsof: correct check for symbolic link
Busybox lsof used the d_type field of a 'struct dirent' to verify whether the
entry is a symbolic link. This field, however, is not portable. On at least
one board [1] I have seen, that field is 0, and the check fails even though
the entry is a link.
The explicit check for a symbolic link is really only needed to skip the
default directory entries '.' and '..'. The directory /proc/<pid>/fd/
should not contain anything else but these two and symbolic links.
With these assumptions, this patch replaces the explicit link check with a
basic check for '.' and '..' (and any hidden file). In the unlikely case that
there are other file types, xmalloc_readlink() will return NULL, and we can
skip the entry.
[1] A MIPS-based board with glibc 2.9, Linux 2.6.32.27.
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/lsof.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/procps/lsof.c b/procps/lsof.c index 7e0ffa4e5..b0156a538 100644 --- a/procps/lsof.c +++ b/procps/lsof.c | |||
@@ -61,9 +61,12 @@ int lsof_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
61 | d_fd = opendir(name); | 61 | d_fd = opendir(name); |
62 | if (d_fd) { | 62 | if (d_fd) { |
63 | while ((entry = readdir(d_fd)) != NULL) { | 63 | while ((entry = readdir(d_fd)) != NULL) { |
64 | if (entry->d_type == DT_LNK) { | 64 | /* Skip entries '.' and '..' (and any hidden file) */ |
65 | safe_strncpy(name + baseofs, entry->d_name, 10); | 65 | if (entry->d_name[0] == '.') |
66 | fdlink = xmalloc_readlink(name); | 66 | continue; |
67 | |||
68 | safe_strncpy(name + baseofs, entry->d_name, 10); | ||
69 | if ((fdlink = xmalloc_readlink(name)) != NULL) { | ||
67 | printf("%d\t%s\t%s\n", proc->pid, proc->exe, fdlink); | 70 | printf("%d\t%s\t%s\n", proc->pid, proc->exe, fdlink); |
68 | free(fdlink); | 71 | free(fdlink); |
69 | } | 72 | } |