-_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
- int r;
- char *root, *cgroup, *p, *cc;
- struct stat st;
-
- if (pid < 0)
- return -EINVAL;
-
- if (!uid)
- return -EINVAL;
-
- r = cg_pid_get_path_shifted(pid, &root, &cgroup);
- if (r < 0)
- return r;
-
- if (!startswith(cgroup, "/user/")) {
- free(cgroup);
- free(root);
- return -ENOENT;
- }
-
- p = strchr(cgroup + 6, '/');
- if (!p) {
- free(cgroup);
- return -ENOENT;
- }
-
- p++;
- p += strcspn(p, "/");
- *p = 0;