mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
bootmisc: Replace homegrown desym() with realpath()
Followup to issue #49. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
47060c9738
commit
b9ae4d04ef
1 file changed
+9
-23
+9
-23
@@ -32,39 +32,23 @@
|
|||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
#include "../utmp-api.h"
|
#include "../utmp-api.h"
|
||||||
|
|
||||||
/* Resolve symbolic links */
|
static int is_tmpfs(char *path)
|
||||||
static char *desym(char *dir)
|
|
||||||
{
|
|
||||||
static char path[80]; /* Should be enough for our use-case */
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (stat(dir, &st))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (S_ISLNK(st.st_mode)) {
|
|
||||||
if (-1 == readlink(dir, path, sizeof(path)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return desym(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_tmpfs(char *dir)
|
|
||||||
{
|
{
|
||||||
int tmpfs = 0;
|
int tmpfs = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char *dir;
|
||||||
struct mntent *mnt;
|
struct mntent *mnt;
|
||||||
|
|
||||||
/* If /var/run is a symlink, check what it resolves to */
|
/* If path is a symlink, check what it resolves to */
|
||||||
dir = desym(dir);
|
dir = realpath(path, NULL);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return 0; /* Outlook not so good */
|
return 0; /* Outlook not so good */
|
||||||
|
|
||||||
fp = setmntent("/proc/mounts", "r");
|
fp = setmntent("/proc/mounts", "r");
|
||||||
if (!fp)
|
if (!fp) {
|
||||||
|
free(dir);
|
||||||
return 0; /* Dunno, maybe not */
|
return 0; /* Dunno, maybe not */
|
||||||
|
}
|
||||||
|
|
||||||
while ((mnt = getmntent(fp))) {
|
while ((mnt = getmntent(fp))) {
|
||||||
if (!strcmp(dir, mnt->mnt_dir))
|
if (!strcmp(dir, mnt->mnt_dir))
|
||||||
@@ -73,7 +57,9 @@ static int is_tmpfs(char *dir)
|
|||||||
|
|
||||||
if (mnt && !strcmp("tmpfs", mnt->mnt_type))
|
if (mnt && !strcmp("tmpfs", mnt->mnt_type))
|
||||||
tmpfs = 1;
|
tmpfs = 1;
|
||||||
|
|
||||||
endmntent(fp);
|
endmntent(fp);
|
||||||
|
free(dir);
|
||||||
|
|
||||||
return tmpfs;
|
return tmpfs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user