]> git.proxmox.com Git - mirror_lxc.git/commitdiff
cgroups/cgfsng: rework cgfsng_monitor_create()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 7 Dec 2019 17:12:30 +0000 (18:12 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 7 Dec 2019 23:10:30 +0000 (00:10 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/log.h

index 2549ca628e2d166470452c714b9a0e539cf8dfe0..aa90842ffa3ce9faebb527148724b346980c48f4 100644 (file)
@@ -1303,14 +1303,22 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
        char *offset, *tmp;
        int i, idx = 0;
        size_t len;
-       struct lxc_conf *conf = handler->conf;
+       struct lxc_conf *conf;
 
-       if (!conf)
-               return false;
+       if (!ops)
+               return ret_set_errno(false, ENOENT);
 
        if (!ops->hierarchies)
                return true;
 
+       if (ops->monitor_cgroup)
+               return ret_set_errno(false, EEXIST);
+
+       if (!handler || !handler->conf)
+               return ret_set_errno(false, EINVAL);
+
+       conf = handler->conf;
+
        if (conf->cgroup_meta.dir)
                tmp = lxc_string_join("/",
                                      (const char *[]){conf->cgroup_meta.dir,
@@ -1320,7 +1328,7 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
        else
                tmp = must_make_path(ops->monitor_pattern, handler->name, NULL);
        if (!tmp)
-               return false;
+               return ret_set_errno(false, ENOMEM);
 
        len = strlen(tmp) + 5; /* leave room for -NNN\0 */
        monitor_cgroup = must_realloc(tmp, len);
@@ -1328,11 +1336,8 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
        *offset = 0;
 
        do {
-               if (idx) {
-                       int ret = snprintf(offset, 5, "-%d", idx);
-                       if (ret < 0 || (size_t)ret >= 5)
-                               return false;
-               }
+               if (idx)
+                       sprintf(offset, "-%d", idx);
 
                for (i = 0; ops->hierarchies[i]; i++) {
                        if (!monitor_create_path_for_hierarchy(ops->hierarchies[i],
@@ -1351,11 +1356,10 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
        } while (ops->hierarchies[i] && idx > 0 && idx < 1000);
 
        if (idx == 1000)
-               return false;
+               return ret_set_errno(false, ERANGE);
 
-       INFO("The monitor process uses \"%s\" as cgroup", monitor_cgroup);
        ops->monitor_cgroup = move_ptr(monitor_cgroup);
-       return true;
+       return log_info(true, "The monitor process uses \"%s\" as cgroup", monitor_cgroup);
 }
 
 /* Try to create the same cgroup in all hierarchies. Start with cgroup_pattern;
index 1d5d444b4e0c6852655567c117c0f4f726bf9049..5305d55b62facc1079fcabc340547f93f06ef0f1 100644 (file)
@@ -512,7 +512,7 @@ __unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,    \
 
 #define log_debug_errno(__ret__, __errno__, format, ...) \
        ({                                               \
-               errno = __errno__;                      \
+               errno = __errno__;                       \
                SYSDEBUG(format, ##__VA_ARGS__);         \
                __ret__;                                 \
        })
@@ -523,6 +523,12 @@ __unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,   \
                __ret__;                      \
        })
 
+#define log_info(__ret__, format, ...)       \
+       ({                                   \
+               INFO(format, ##__VA_ARGS__); \
+               __ret__;                     \
+       })
+
 extern int lxc_log_fd;
 
 extern int lxc_log_syslog(int facility);