diff options
author | Matt Kraai | 2001-05-23 14:45:09 +0000 |
---|---|---|
committer | Matt Kraai | 2001-05-23 14:45:09 +0000 |
commit | 774d135b66f4ba914ee8649ce6e8c3f7d3e36c35 (patch) | |
tree | b308aeef4bb165d343a8971b8a12325846aab7af /libbb/find_root_device.c | |
parent | 3200f5ac689288b830a572e43dbdfd35bdac119c (diff) | |
download | busybox-774d135b66f4ba914ee8649ce6e8c3f7d3e36c35.zip busybox-774d135b66f4ba914ee8649ce6e8c3f7d3e36c35.tar.gz |
Make more robust (patch by Larry Doolittle).
Diffstat (limited to 'libbb/find_root_device.c')
-rw-r--r-- | libbb/find_root_device.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index 75ed1a9..edfd708 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; } |