#include <string.h>
#include <stdlib.h>
#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "cgroup-util.h"
#include "log.h"
if ((r = cg_get_path(controller, path, NULL, &fs)) < 0)
return r;
- r = mkdir_p(fs, 0755);
+ r = mkdir_parents(fs, 0755);
+
+ if (r >= 0) {
+ if (mkdir(fs, 0755) >= 0)
+ r = 1;
+ else if (errno == EEXIST)
+ r = 0;
+ else
+ r = -errno;
+ }
+
free(fs);
return r;
}
int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
- int r;
+ int r, q;
assert(controller);
assert(path);
if ((r = cg_create(controller, path)) < 0)
return r;
- if ((r = cg_attach(controller, path, pid)) < 0)
- return r;
+ if ((q = cg_attach(controller, path, pid)) < 0)
+ return q;
/* This does not remove the cgroup on failure */
free(fs);
fs = NULL;
- if ((r = cg_get_path(controller, NULL, "notify_on_release", &fs)) < 0) {
- r = -ENOMEM;
+ if ((r = cg_get_path(controller, NULL, "notify_on_release", &fs)) < 0)
goto finish;
- }
free(contents);
contents = NULL;