aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-05-23 14:45:09 +0000
committerMatt Kraai <kraai@debian.org>2001-05-23 14:45:09 +0000
commit774d135b66f4ba914ee8649ce6e8c3f7d3e36c35 (patch)
treeb308aeef4bb165d343a8971b8a12325846aab7af /libbb
parent3200f5ac689288b830a572e43dbdfd35bdac119c (diff)
downloadbusybox-774d135b66f4ba914ee8649ce6e8c3f7d3e36c35.tar.gz
Make more robust (patch by Larry Doolittle).
Diffstat (limited to 'libbb')
-rw-r--r--libbb/find_root_device.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 75ed1a979..edfd7085a 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -39,16 +39,18 @@ extern char *find_real_root_device_name(const char* name)
struct dirent *entry;
struct stat statBuf, rootStat;
char *fileName;
+ dev_t dev;
if (stat("/", &rootStat) != 0) {
- error_msg("could not stat '/'");
+ perror_msg("could not stat '/'");
return NULL;
}
+ if ((dev = rootStat.st_rdev)==0) dev=rootStat.st_dev;
dir = opendir("/dev");
if (!dir) {
- error_msg("could not open '/dev'");
- return NULL;
+ perror_msg("could not open '/dev'");
+ goto fallback;
}
while((entry = readdir(dir)) != NULL) {
@@ -64,14 +66,18 @@ extern char *find_real_root_device_name(const char* name)
* devices, so make sure this is a block device */
if (stat(fileName, &statBuf) == 0 &&
S_ISBLK(statBuf.st_mode)!=0 &&
- statBuf.st_rdev == rootStat.st_rdev) {
+ statBuf.st_rdev == dev) {
return fileName;
}
free(fileName);
}
closedir(dir);
- return NULL;
+fallback:
+ /* don't use stack space, caller expects to free() result */
+ fileName=xmalloc(20);
+ sprintf(fileName,"(rdev %u)",(unsigned int) rootStat.st_rdev);
+ return fileName;
}