mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
cgroup-util: add pidref+full counter parts for cg_pid_get_user_unit()
This completes the set of functions for getting the user unit of a process, mirroring the four functions we already have for the system unit.
This commit is contained in:
committed by
Daan De Meyer
parent
ece4df0293
commit
015025cba2
@@ -1157,7 +1157,7 @@ static const char* skip_user_prefix(const char *path) {
|
||||
return skip_session(e);
|
||||
}
|
||||
|
||||
int cg_path_get_user_unit(const char *path, char **ret) {
|
||||
int cg_path_get_user_unit_full(const char *path, char **ret_unit, char **ret_subgroup) {
|
||||
const char *t;
|
||||
|
||||
assert(path);
|
||||
@@ -1168,18 +1168,42 @@ int cg_path_get_user_unit(const char *path, char **ret) {
|
||||
|
||||
/* And from here on it looks pretty much the same as for a system unit, hence let's use the same
|
||||
* parser. */
|
||||
return cg_path_get_unit(t, ret);
|
||||
return cg_path_get_unit_full(t, ret_unit, ret_subgroup);
|
||||
}
|
||||
|
||||
int cg_pid_get_user_unit(pid_t pid, char **ret_unit) {
|
||||
_cleanup_free_ char *cgroup = NULL;
|
||||
int cg_pid_get_user_unit_full(pid_t pid, char **ret_unit, char **ret_subgroup) {
|
||||
int r;
|
||||
|
||||
_cleanup_free_ char *cgroup = NULL;
|
||||
r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return cg_path_get_user_unit(cgroup, ret_unit);
|
||||
return cg_path_get_user_unit_full(cgroup, ret_unit, ret_subgroup);
|
||||
}
|
||||
|
||||
int cg_pidref_get_user_unit_full(const PidRef *pidref, char **ret_unit, char **ret_subgroup) {
|
||||
int r;
|
||||
|
||||
if (!pidref_is_set(pidref))
|
||||
return -ESRCH;
|
||||
if (pidref_is_remote(pidref))
|
||||
return -EREMOTE;
|
||||
|
||||
_cleanup_free_ char *unit = NULL, *subgroup = NULL;
|
||||
r = cg_pid_get_user_unit_full(pidref->pid, &unit, &subgroup);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = pidref_verify(pidref);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (ret_unit)
|
||||
*ret_unit = TAKE_PTR(unit);
|
||||
if (ret_subgroup)
|
||||
*ret_subgroup = TAKE_PTR(subgroup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cg_path_get_machine_name(const char *path, char **ret_machine) {
|
||||
|
@@ -208,7 +208,10 @@ static inline int cg_path_get_unit(const char *path, char **ret_unit) {
|
||||
return cg_path_get_unit_full(path, ret_unit, NULL);
|
||||
}
|
||||
int cg_path_get_unit_path(const char *path, char **ret_unit);
|
||||
int cg_path_get_user_unit(const char *path, char **ret_unit);
|
||||
int cg_path_get_user_unit_full(const char *path, char **ret_unit, char **ret_subgroup);
|
||||
static inline int cg_path_get_user_unit(const char *path, char **ret_unit) {
|
||||
return cg_path_get_user_unit_full(path, ret_unit, NULL);
|
||||
}
|
||||
int cg_path_get_machine_name(const char *path, char **ret_machine);
|
||||
int cg_path_get_slice(const char *path, char **ret_slice);
|
||||
int cg_path_get_user_slice(const char *path, char **ret_slice);
|
||||
@@ -228,7 +231,14 @@ int cg_pidref_get_unit_full(const PidRef *pidref, char **ret_unit, char **ret_su
|
||||
static inline int cg_pidref_get_unit(const PidRef *pidref, char **ret_unit) {
|
||||
return cg_pidref_get_unit_full(pidref, ret_unit, NULL);
|
||||
}
|
||||
int cg_pid_get_user_unit(pid_t pid, char **ret_unit);
|
||||
int cg_pid_get_user_unit_full(pid_t pid, char **ret_unit, char **ret_subgroup);
|
||||
static inline int cg_pid_get_user_unit(pid_t pid, char **ret_unit) {
|
||||
return cg_pid_get_unit_full(pid, ret_unit, NULL);
|
||||
}
|
||||
int cg_pidref_get_user_unit_full(const PidRef *pidref, char **ret_unit, char **ret_subgroup);
|
||||
static inline int cg_pidref_get_user_unit(const PidRef *pidref, char **ret_unit) {
|
||||
return cg_pidref_get_user_unit_full(pidref, ret_unit, NULL);
|
||||
}
|
||||
int cg_pid_get_machine_name(pid_t pid, char **ret_machine);
|
||||
int cg_pid_get_slice(pid_t pid, char **ret_slice);
|
||||
int cg_pid_get_user_slice(pid_t pid, char **ret_slice);
|
||||
|
@@ -1483,7 +1483,7 @@ static int gather_pid_metadata_from_procfs(struct iovec_wrapper *iovw, Context *
|
||||
if (cg_pidref_get_unit(&context->pidref, &t) >= 0)
|
||||
(void) iovw_put_string_field_free(iovw, "COREDUMP_UNIT=", t);
|
||||
|
||||
if (cg_pid_get_user_unit(pid, &t) >= 0)
|
||||
if (cg_pidref_get_user_unit(&context->pidref, &t) >= 0)
|
||||
(void) iovw_put_string_field_free(iovw, "COREDUMP_USER_UNIT=", t);
|
||||
|
||||
if (cg_pidref_get_session(&context->pidref, &t) >= 0)
|
||||
|
Reference in New Issue
Block a user