mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
implement upwards path traversal to find fs type
* yes, this is a feature and right now there is something like a feature freeze. * BUT I tested this with: /, /tmp, /dev/mapper, /dev, //, /mnt/, /tmp/bla (the last one was non-existent, creating it during runtime and even mounting tmpfs on it led to expected results. git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1074 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
9d4c7ed14e
commit
5c4fee8d32
26
src/fs.c
26
src/fs.c
@ -138,10 +138,11 @@ void get_fs_type(const char *path, char *result)
|
|||||||
|
|
||||||
#else /* HAVE_STRUCT_STATFS_F_FSTYPENAME */
|
#else /* HAVE_STRUCT_STATFS_F_FSTYPENAME */
|
||||||
|
|
||||||
/* TODO: walk up the directory tree so it works on on paths that are not actually mount points. */
|
|
||||||
|
|
||||||
struct mntent *me;
|
struct mntent *me;
|
||||||
FILE *mtab = setmntent("/etc/mtab", "r");
|
FILE *mtab = setmntent("/etc/mtab", "r");
|
||||||
|
char *search_path;
|
||||||
|
int match;
|
||||||
|
char *slash;
|
||||||
|
|
||||||
if (mtab == NULL) {
|
if (mtab == NULL) {
|
||||||
ERR("setmntent /etc/mtab: %s", strerror(errno));
|
ERR("setmntent /etc/mtab: %s", strerror(errno));
|
||||||
@ -152,11 +153,28 @@ void get_fs_type(const char *path, char *result)
|
|||||||
me = getmntent(mtab);
|
me = getmntent(mtab);
|
||||||
|
|
||||||
// find our path in the mtab
|
// find our path in the mtab
|
||||||
while (strcmp(path, me->mnt_dir) && getmntent(mtab));
|
search_path = strdup(path);
|
||||||
|
do {
|
||||||
|
while ((match = strcmp(search_path, me->mnt_dir))
|
||||||
|
&& getmntent(mtab));
|
||||||
|
if (!match)
|
||||||
|
break;
|
||||||
|
fseek(mtab, 0, SEEK_SET);
|
||||||
|
slash = strrchr(search_path, '/');
|
||||||
|
if (slash == NULL)
|
||||||
|
CRIT_ERR("invalid path '%s'", path);
|
||||||
|
if (strlen(slash) == 1) /* trailing slash */
|
||||||
|
*(slash) = '\0';
|
||||||
|
else if (strlen(slash) > 1)
|
||||||
|
*(slash + 1) = '\0';
|
||||||
|
else
|
||||||
|
CRIT_ERR("found a crack in the matrix!");
|
||||||
|
} while (strlen(search_path) > 0);
|
||||||
|
free(search_path);
|
||||||
|
|
||||||
endmntent(mtab);
|
endmntent(mtab);
|
||||||
|
|
||||||
if (me && !strcmp(path, me->mnt_dir)) {
|
if (me && !match) {
|
||||||
strncpy(result, me->mnt_type, DEFAULT_TEXT_BUFFER_SIZE);
|
strncpy(result, me->mnt_type, DEFAULT_TEXT_BUFFER_SIZE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user