diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:42:16 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:42:16 +0000 |
commit | c911a4389bbaa5ac85d725c8c05e452dfba8583d (patch) | |
tree | a0f435a6239c002578db8f019eb0fb427f1795b3 /libbb/find_root_device.c | |
parent | 15649c11f3568ed6f030953844f201438379e03c (diff) |
Patch from Vladimir:
1) fixed a bug that could crash df, mount, and umount applets if the root
device name was longer then the word "root" (/dev/loop1 vs /dev/root) -
2) severl functions needed static declaration in the umount applet
3) update declaration for function in last_char_is() in libbb
Diffstat (limited to 'libbb/find_root_device.c')
-rw-r--r-- | libbb/find_root_device.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index de765ce44..75ed1a979 100644 --- a/libbb/find_root_device.c +++ b/libbb/find_root_device.c @@ -28,26 +28,27 @@ #include <stdio.h> #include <string.h> #include <dirent.h> +#include <stdlib.h> #include "libbb.h" -extern int find_real_root_device_name(char* name) +extern char *find_real_root_device_name(const char* name) { DIR *dir; struct dirent *entry; struct stat statBuf, rootStat; - char fileName[BUFSIZ]; + char *fileName; if (stat("/", &rootStat) != 0) { error_msg("could not stat '/'"); - return( FALSE); + return NULL; } dir = opendir("/dev"); if (!dir) { error_msg("could not open '/dev'"); - return( FALSE); + return NULL; } while((entry = readdir(dir)) != NULL) { @@ -57,21 +58,20 @@ extern int find_real_root_device_name(char* name) if (strcmp(entry->d_name, "..") == 0) continue; - snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name); + fileName = concat_path_file("/dev/", entry->d_name); - if (stat(fileName, &statBuf) != 0) - continue; /* Some char devices have the same dev_t as block * devices, so make sure this is a block device */ - if (! S_ISBLK(statBuf.st_mode)) - continue; - if (statBuf.st_rdev == rootStat.st_rdev) { - strcpy(name, fileName); - return ( TRUE); + if (stat(fileName, &statBuf) == 0 && + S_ISBLK(statBuf.st_mode)!=0 && + statBuf.st_rdev == rootStat.st_rdev) { + return fileName; } + free(fileName); } + closedir(dir); - return( FALSE); + return NULL; } |