Signed-off-by: Markus Gothe <nietzsche@lysator.liu.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
#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;
struct dirent *de;
DIR *dir;
- xchdir("/sys/bus/scsi/devices");
+ xchdir(scsi_dir);
dir = xopendir(".");
while ((de = readdir(dir)) != NULL) {
);
/* 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)