int cg_create(const char *controller, const char *path, const char *suffix) { _cleanup_free_ char *fs = NULL; int r; #ifdef HAVE_CGMANAGER /* CGManager support */ int existed; if (cgm_dbus_connect()) { if (!controller) { cgm_dbus_disconnect(); return -1; } r = cgm_create(normalize_controller(controller), path, &existed); cgm_dbus_disconnect(); if (!r) return -1; return 1; } #endif r = cg_get_path_and_check(controller, path, suffix, &fs); if (r < 0) return r; r = mkdir_parents_label(fs, 0755); if (r < 0) return r; if (mkdir(fs, 0755) < 0) { if (errno == EEXIST) return 0; return -errno; } return 1; }
int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) { const char *p; int r; assert(controller); assert(fs); if (isempty(controller)) return -EINVAL; /* Normalize the controller syntax */ p = normalize_controller(controller); /* Check if this controller actually really exists */ r = check(p); if (r < 0) return r; return join_path(p, path, suffix, fs); }
int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) { const char *p; static __thread bool good = false; assert(fs); if (_unlikely_(!good)) { int r; r = path_is_mount_point("/sys/fs/cgroup", false); if (r <= 0) return r < 0 ? r : -ENOENT; /* Cache this to save a few stat()s */ good = true; } p = controller ? normalize_controller(controller) : NULL; return join_path(p, path, suffix, fs); }