Skip to content

Commit

Permalink
bootclean: Resolve any symlinks in tmpfs check
Browse files Browse the repository at this point in the history
Followup to issue #49.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
  • Loading branch information
troglobit committed Nov 21, 2016
1 parent 846692c commit 47060c9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions plugins/bootmisc.c
Expand Up @@ -32,12 +32,36 @@
#include "../plugin.h"
#include "../utmp-api.h"

/* Resolve symbolic links */
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;
FILE *fp;
struct mntent *mnt;

/* If /var/run is a symlink, check what it resolves to */
dir = desym(dir);
if (!dir)
return 0; /* Outlook not so good */

fp = setmntent("/proc/mounts", "r");
if (!fp)
return 0; /* Dunno, maybe not */
Expand Down

0 comments on commit 47060c9

Please sign in to comment.