Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logind: register PAM sessions via Varlink instead of D-Bus #35264

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cgroup-util: add pidref counterparts for cg_pid_get_session() + cg_pi…
…d_get_owner_uid()
  • Loading branch information
poettering committed Dec 18, 2024
commit 40f75ba2d0d1b348e07ae6e6df8a84016c53d45f
41 changes: 41 additions & 0 deletions src/basic/cgroup-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,26 @@ int cg_pid_get_session(pid_t pid, char **ret_session) {
return cg_path_get_session(cgroup, ret_session);
}

int cg_pidref_get_session(const PidRef *pidref, char **ret) {
int r;

if (!pidref_is_set(pidref))
return -ESRCH;

_cleanup_free_ char *session = NULL;
r = cg_pid_get_session(pidref->pid, &session);
if (r < 0)
return r;

r = pidref_verify(pidref);
if (r < 0)
return r;

if (ret)
*ret = TAKE_PTR(session);
return 0;
}

int cg_path_get_owner_uid(const char *path, uid_t *ret_uid) {
_cleanup_free_ char *slice = NULL;
char *start, *end;
Expand Down Expand Up @@ -1439,6 +1459,27 @@ int cg_pid_get_owner_uid(pid_t pid, uid_t *ret_uid) {
return cg_path_get_owner_uid(cgroup, ret_uid);
}

int cg_pidref_get_owner_uid(const PidRef *pidref, uid_t *ret) {
int r;

if (!pidref_is_set(pidref))
return -ESRCH;

uid_t uid;
r = cg_pid_get_owner_uid(pidref->pid, &uid);
if (r < 0)
return r;

r = pidref_verify(pidref);
if (r < 0)
return r;

if (ret)
*ret = uid;

return 0;
}

int cg_path_get_slice(const char *p, char **ret_slice) {
const char *e = NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/basic/cgroup-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ int cg_shift_path(const char *cgroup, const char *cached_root, const char **ret_
int cg_pid_get_path_shifted(pid_t pid, const char *cached_root, char **ret_cgroup);

int cg_pid_get_session(pid_t pid, char **ret_session);
int cg_pidref_get_session(const PidRef *pidref, char **ret_session);
int cg_pid_get_owner_uid(pid_t pid, uid_t *ret_uid);
int cg_pidref_get_owner_uid(const PidRef *pidref, uid_t *ret_uid);
int cg_pid_get_unit(pid_t pid, char **ret_unit);
int cg_pidref_get_unit(const PidRef *pidref, char **ret);
int cg_pid_get_user_unit(pid_t pid, char **ret_unit);
Expand Down
4 changes: 2 additions & 2 deletions src/test/test-cgroup-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ TEST(proc) {

cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid.pid, &path);
cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted);
cg_pid_get_owner_uid(pid.pid, &uid);
cg_pid_get_session(pid.pid, &session);
cg_pidref_get_owner_uid(&pid, &uid);
cg_pidref_get_session(&pid, &session);
cg_pid_get_unit(pid.pid, &unit);
cg_pid_get_user_unit(pid.pid, &user_unit);
cg_pid_get_machine_name(pid.pid, &machine);
Expand Down