main: check immediately if mknod is usable

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-07-13 23:43:25 +02:00
parent 8d2aedcb19
commit afbb9049da
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

17
main.c
View File

@ -312,6 +312,22 @@ strconcat3 (char *dest, size_t size, const char *s1, const char *s2, const char
return current - dest; return current - dest;
} }
static void
check_can_mknod (struct ovl_data *lo)
{
int ret;
char path[PATH_MAX];
sprintf (path, "%lu", get_next_wd_counter ());
ret = mknodat (lo->workdir_fd, path, S_IFCHR|0700, makedev (0, 0));
if (ret == 0)
unlinkat (lo->workdir_fd, path, 0);
if (ret < 0 && errno == EPERM)
can_mknod = false;
}
static struct ovl_mapping * static struct ovl_mapping *
read_mappings (const char *str) read_mappings (const char *str)
{ {
@ -4056,6 +4072,7 @@ main (int argc, char *argv[])
} }
set_limits (); set_limits ();
check_can_mknod (&lo);
if (lo.debug) if (lo.debug)
{ {