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>
This commit is contained in:
parent
14c85eb7db
commit
045327a418
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#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)
|
static char *get_line(const char *filename, char *buf, unsigned *bufsize_p)
|
||||||
{
|
{
|
||||||
unsigned bufsize = *bufsize_p;
|
unsigned bufsize = *bufsize_p;
|
||||||
@ -53,7 +55,7 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
|||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
xchdir("/sys/bus/scsi/devices");
|
xchdir(scsi_dir);
|
||||||
|
|
||||||
dir = xopendir(".");
|
dir = xopendir(".");
|
||||||
while ((de = readdir(dir)) != NULL) {
|
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" */
|
/* 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)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
|
Loading…
Reference in New Issue
Block a user