- char *root = NULL;
- const char *t = NULL;
-
- r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &root);
- if (r < 0)
- t = "/";
- else {
- if (endswith(root, "/system"))
- root[strlen(root)-7] = 0;
-
- t = root[0] ? root : "/";
+ if (arg_machine) {
+ char *m;
+ const char *cgroup;
+ _cleanup_free_ char *scope = NULL;
+ _cleanup_free_ char *path = NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+
+ m = strappenda("/run/systemd/machines/", arg_machine);
+ r = parse_env_file(m, NEWLINE, "SCOPE", &scope, NULL);
+ if (r < 0) {
+ log_error_errno(r, "Failed to get machine path: %m");
+ goto finish;
+ }
+
+ path = unit_dbus_path_from_name(scope);
+ if (!path) {
+ log_oom();
+ goto finish;
+ }
+
+ r = sd_bus_get_property(
+ bus,
+ "org.freedesktop.systemd1",
+ path,
+ "org.freedesktop.systemd1.Scope",
+ "ControlGroup",
+ &error,
+ &reply,
+ "s");
+
+ if (r < 0) {
+ log_error("Failed to query ControlGroup: %s", bus_error_message(&error, -r));
+ goto finish;
+ }
+
+ r = sd_bus_message_read(reply, "s", &cgroup);
+ if (r < 0) {
+ bus_log_parse_error(r);
+ goto finish;
+ }
+
+ root = strdup(cgroup);
+ if (!root) {
+ log_oom();
+ goto finish;
+ }
+
+ } else
+ r = cg_get_root_path(&root);
+ if (r < 0) {
+ log_error_errno(r, "Failed to get %s path: %m",
+ arg_machine ? "machine" : "root");
+ goto finish;