summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Puccetti <alessandro@kinvolk.io>2016-07-22 15:59:14 +0200
committerLennart Poettering <lennart@poettering.net>2016-07-22 15:59:14 +0200
commitb3d1d51603408e7aea7971fabf41b38c9e12fd69 (patch)
tree083fa997971db1ca14bcba824a39ac6fe6270cd5
parent2424b6bd716f0c1c3bf3406b1fd1a16ba1b6a556 (diff)
namespace: ensure to return a valid inaccessible nodes (#3778)
Because /run/systemd/inaccessible/{chr,blk} are devices with major=0 and minor=0 it might be possible that these devices cannot be created so we use /run/systemd/inaccessible/sock instead to map them.
-rw-r--r--src/basic/mount-util.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c
index 63dff3dd5c..b91f0f9e0e 100644
--- a/src/basic/mount-util.c
+++ b/src/basic/mount-util.c
@@ -534,15 +534,22 @@ int repeat_unmount(const char *path, int flags) {
}
const char* mode_to_inaccessible_node(mode_t mode) {
+ /* This function maps a node type to the correspondent inaccessible node type.
+ * Character and block inaccessible devices may not be created (because major=0 and minor=0),
+ * in such case we map character and block devices to the inaccessible node type socket. */
switch(mode & S_IFMT) {
case S_IFREG:
return "/run/systemd/inaccessible/reg";
case S_IFDIR:
return "/run/systemd/inaccessible/dir";
case S_IFCHR:
- return "/run/systemd/inaccessible/chr";
+ if (access("/run/systemd/inaccessible/chr", F_OK) == 0)
+ return "/run/systemd/inaccessible/chr";
+ return "/run/systemd/inaccessible/sock";
case S_IFBLK:
- return "/run/systemd/inaccessible/blk";
+ if (access("/run/systemd/inaccessible/blk", F_OK) == 0)
+ return "/run/systemd/inaccessible/blk";
+ return "/run/systemd/inaccessible/sock";
case S_IFIFO:
return "/run/systemd/inaccessible/fifo";
case S_IFSOCK: