chiark / gitweb /
cgroup: properly check for ignore-notfound paths (#4803)
authorDave Reisner <d@falconindy.com>
Fri, 2 Dec 2016 14:23:23 +0000 (09:23 -0500)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:35 +0000 (17:58 +0200)
Follow-up to #4687 and e7330dfe14b1965f.

src/core/cgroup.c

index e44f729246572d4ecfd653fc4736c10cc0c4eb9d..1e14d9fc416d6f416f8f2c810eb469440c141127 100644 (file)
@@ -288,14 +288,21 @@ 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) {
-                /* path starting with "-" must be silently ignored */
-                if (errno == ENOENT && startswith(node, "-"))
+                if (errno == ENOENT && ignore_notfound)
                         return 0;
 
                 return log_warning_errno(errno, "Couldn't stat device %s: %m", node);