X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fcgroup.c;h=1e14d9fc416d6f416f8f2c810eb469440c141127;hb=f6c8671cc2984c6448d6b1039c0091c93319966a;hp=9e4e993263916428dd636c0958f7fb642002fba5;hpb=f5eb2a086bc5d5d36bc2e4755a1d6b508e202250;p=elogind.git diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 9e4e99326..1e14d9fc4 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -288,14 +288,24 @@ static int lookup_block_device(const char *p, dev_t *dev) { static int whitelist_device(const char *path, const char *node, const char *acc) { char buf[2+DECIMAL_STR_MAX(dev_t)*2+2+4]; struct stat st; + bool ignore_notfound; int r; assert(path); assert(acc); + if (node[0] == '-') { + /* Non-existent paths starting with "-" must be silently ignored */ + node++; + ignore_notfound = true; + } else + ignore_notfound = false; + if (stat(node, &st) < 0) { - log_warning("Couldn't stat device %s", node); - return -errno; + if (errno == ENOENT && ignore_notfound) + return 0; + + return log_warning_errno(errno, "Couldn't stat device %s: %m", node); } if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) { @@ -916,8 +926,8 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) { "/dev/pts/ptmx\0" "rw\0" /* /dev/pts/ptmx may not be duplicated, but accessed */ /* Allow /run/elogind/inaccessible/{chr,blk} devices for mapping InaccessiblePaths */ /* Allow /run/systemd/inaccessible/{chr,blk} devices for mapping InaccessiblePaths */ - "/run/systemd/inaccessible/chr\0" "rwm\0" - "/run/systemd/inaccessible/blk\0" "rwm\0"; + "-/run/systemd/inaccessible/chr\0" "rwm\0" + "-/run/systemd/inaccessible/blk\0" "rwm\0"; const char *x, *y; @@ -930,7 +940,7 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) { } LIST_FOREACH(device_allow, a, c->device_allow) { - char acc[4]; + char acc[4], *val; unsigned k = 0; if (a->r) @@ -947,10 +957,10 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) { if (startswith(a->path, "/dev/")) whitelist_device(path, a->path, acc); - else if (startswith(a->path, "block-")) - whitelist_major(path, a->path + 6, 'b', acc); - else if (startswith(a->path, "char-")) - whitelist_major(path, a->path + 5, 'c', acc); + else if ((val = startswith(a->path, "block-"))) + whitelist_major(path, val, 'b', acc); + else if ((val = startswith(a->path, "char-"))) + whitelist_major(path, val, 'c', acc); else log_unit_debug(u, "Ignoring device %s while writing cgroup attribute.", a->path); } @@ -1203,9 +1213,10 @@ char *unit_default_cgroup_path(Unit *u) { return NULL; if (slice) - return strjoin(u->manager->cgroup_root, "/", slice, "/", escaped, NULL); + return strjoin(u->manager->cgroup_root, "/", slice, "/", + escaped); else - return strjoin(u->manager->cgroup_root, "/", escaped, NULL); + return strjoin(u->manager->cgroup_root, "/", escaped); } int unit_set_cgroup_path(Unit *u, const char *path) { @@ -1645,7 +1656,7 @@ static int unit_watch_pids_in_path(Unit *u, const char *path) { while ((r = cg_read_subgroup(d, &fn)) > 0) { _cleanup_free_ char *p = NULL; - p = strjoin(path, "/", fn, NULL); + p = strjoin(path, "/", fn); free(fn); if (!p)