-static int setup_cgroup(const char *path) {
- char **c;
- int r;
-
- r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, path, 1);
- if (r < 0) {
- log_error("Failed to create cgroup: %s", strerror(-r));
- return r;
- }
-
- STRV_FOREACH(c, arg_controllers) {
- r = cg_create_and_attach(*c, path, 1);
- if (r < 0)
- log_warning("Failed to create cgroup in controller %s: %s", *c, strerror(-r));
- }
-
- return 0;
-}
-
-static int save_attributes(const char *cgroup, pid_t pid, const char *uuid, const char *directory) {
- _cleanup_free_ char *path = NULL;
- char buf[DECIMAL_STR_MAX(pid_t)];
- int r = 0, k;
-
- assert(cgroup);
- assert(pid >= 0);
- assert(arg_directory);
-
-#ifdef HAVE_XATTR
- assert_se(snprintf(buf, sizeof(buf), "%lu", (unsigned long) pid) < (int) sizeof(buf));
-
- r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, NULL, &path);
- if (r < 0) {
- log_error("Failed to get path: %s", strerror(-r));
- return r;
- }
-
- r = setxattr(path, "trusted.init_pid", buf, strlen(buf), XATTR_CREATE);
- if (r < 0)
- log_warning("Failed to set %s attribute on %s: %m", "trusted.init_pid", path);
-
- if (uuid) {
- k = setxattr(path, "trusted.machine_id", uuid, strlen(uuid), XATTR_CREATE);
- if (k < 0) {
- log_warning("Failed to set %s attribute on %s: %m", "trusted.machine_id", path);
- if (r == 0)
- r = k;
- }
- }
-
- k = setxattr(path, "trusted.root_directory", directory, strlen(directory), XATTR_CREATE);
- if (k < 0) {
- log_warning("Failed to set %s attribute on %s: %m", "trusted.root_directory", path);
- if (r == 0)
- r = k;
- }
-#endif
- return r;
-}
-