X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fnamespace.c;h=718da2384dc21adc294384d26941b7ec7d11713b;hb=340a1d2330ddc1dd18ad75bcdddf32f63c84b4a1;hp=4fecd32363a6baaf9d302e839ee30c157b78691a;hpb=63c372cb9df3bee01e3bf8cd7f96f336bddda846;p=elogind.git diff --git a/src/core/namespace.c b/src/core/namespace.c index 4fecd3236..718da2384 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -25,23 +25,15 @@ #include #include #include -#include #include -#include -#include #include -#include #include "strv.h" #include "util.h" #include "path-util.h" #include "missing.h" -#include "execute.h" #include "loopback-setup.h" -#include "mkdir.h" #include "dev-setup.h" -#include "def.h" -#include "label.h" #include "selinux-util.h" #include "namespace.h" @@ -91,9 +83,11 @@ static int append_mounts(BindMount **p, char **strv, MountMode mode) { static int mount_path_compare(const void *a, const void *b) { const BindMount *p = a, *q = b; + int d; - if (path_equal(p->path, q->path)) { + d = path_compare(p->path, q->path); + if (!d) { /* If the paths are equal, check the mode */ if (p->mode < q->mode) return -1; @@ -105,13 +99,7 @@ static int mount_path_compare(const void *a, const void *b) { } /* If the paths are not equal, then order prefixes first */ - if (path_startswith(p->path, q->path)) - return 1; - - if (path_startswith(q->path, p->path)) - return -1; - - return 0; + return d; } static void drop_duplicates(BindMount *m, unsigned *n) { @@ -158,24 +146,27 @@ static int mount_dev(BindMount *m) { return -errno; dev = strjoina(temporary_mount, "/dev"); - (void)mkdir(dev, 0755); + (void) mkdir(dev, 0755); if (mount("tmpfs", dev, "tmpfs", MS_NOSUID|MS_STRICTATIME, "mode=755") < 0) { r = -errno; goto fail; } devpts = strjoina(temporary_mount, "/dev/pts"); - (void)mkdir(devpts, 0755); + (void) mkdir(devpts, 0755); if (mount("/dev/pts", devpts, NULL, MS_BIND, NULL) < 0) { r = -errno; goto fail; } devptmx = strjoina(temporary_mount, "/dev/ptmx"); - symlink("pts/ptmx", devptmx); + if (symlink("pts/ptmx", devptmx) < 0) { + r = -errno; + goto fail; + } devshm = strjoina(temporary_mount, "/dev/shm"); - (void)mkdir(devshm, 01777); + (void) mkdir(devshm, 01777); r = mount("/dev/shm", devshm, NULL, MS_BIND, NULL); if (r < 0) { r = -errno; @@ -183,15 +174,15 @@ static int mount_dev(BindMount *m) { } devmqueue = strjoina(temporary_mount, "/dev/mqueue"); - (void)mkdir(devmqueue, 0755); - mount("/dev/mqueue", devmqueue, NULL, MS_BIND, NULL); + (void) mkdir(devmqueue, 0755); + (void) mount("/dev/mqueue", devmqueue, NULL, MS_BIND, NULL); devhugepages = strjoina(temporary_mount, "/dev/hugepages"); - (void)mkdir(devhugepages, 0755); - mount("/dev/hugepages", devhugepages, NULL, MS_BIND, NULL); + (void) mkdir(devhugepages, 0755); + (void) mount("/dev/hugepages", devhugepages, NULL, MS_BIND, NULL); devlog = strjoina(temporary_mount, "/dev/log"); - symlink("/run/systemd/journal/dev-log", devlog); + (void) symlink("/run/systemd/journal/dev-log", devlog); NULSTR_FOREACH(d, devnodes) { _cleanup_free_ char *dn = NULL; @@ -281,7 +272,7 @@ static int mount_kdbus(BindMount *m) { return log_error_errno(errno, "Failed create temp dir: %m"); root = strjoina(temporary_mount, "/kdbus"); - (void)mkdir(root, 0755); + (void) mkdir(root, 0755); if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_STRICTATIME, "mode=777") < 0) { r = -errno; goto fail; @@ -302,7 +293,7 @@ static int mount_kdbus(BindMount *m) { goto fail; } - r = mount(m->path, busnode, "bind", MS_BIND, NULL); + r = mount(m->path, busnode, NULL, MS_BIND, NULL); if (r < 0) { log_error_errno(errno, "bind mount of %s failed: %m", m->path); r = -errno; @@ -532,7 +523,7 @@ fail: if (n > 0) { for (m = mounts; m < mounts + n; ++m) if (m->done) - umount2(m->path, MNT_DETACH); + (void) umount2(m->path, MNT_DETACH); } return r;