summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Gothe2017-10-21 21:34:22 +0200
committerDenys Vlasenko2017-10-22 10:43:43 +0200
commit045327a418d1cf0a99405ca0b70ed61b5c1a1869 (patch)
tree2eeb112edb4744608e17d6c7b973c64b183abe18
parent14c85eb7db918daa1914a0e60081b1d3ca12ae04 (diff)
downloadbusybox-045327a418d1cf0a99405ca0b70ed61b5c1a1869.zip
busybox-045327a418d1cf0a99405ca0b70ed61b5c1a1869.tar.gz
lsscsi: fix xchdir("..") from symlink in /sys/bus/scsi/devices
Signed-off-by: Markus Gothe <nietzsche@lysator.liu.se> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/lsscsi.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c
index d7cd510..0aaa01d 100644
--- a/miscutils/lsscsi.c
+++ b/miscutils/lsscsi.c
@@ -25,6 +25,8 @@
#include "libbb.h"
+static const char scsi_dir[] ALIGN1 = "/sys/bus/scsi/devices";
+
static char *get_line(const char *filename, char *buf, unsigned *bufsize_p)
{
unsigned bufsize = *bufsize_p;
@@ -53,7 +55,7 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
struct dirent *de;
DIR *dir;
- xchdir("/sys/bus/scsi/devices");
+ xchdir(scsi_dir);
dir = xopendir(".");
while ((de = readdir(dir)) != NULL) {
@@ -112,7 +114,10 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
);
/* TODO: also output device column, e.g. "/dev/sdX" */
- xchdir("..");
+ /* chdir("..") may not work as expected,
+ * since we might have followed a symlink.
+ */
+ xchdir(scsi_dir);
}
if (ENABLE_FEATURE_CLEAN_UP)