mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
logind: rework manager_get_{user|session}_by_pid() a bit
Let's make sure we always initialize the return value if we return non-negative. Just a matter of coding style: we should always initialize our return values when we return >= 0, and leave them unclobbered if we return < 0.
This commit is contained in:
parent
37cbc1d579
commit
14ef4a6506
@ -282,7 +282,7 @@ int manager_process_button_device(Manager *m, struct udev_device *d) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
|
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **ret) {
|
||||||
_cleanup_free_ char *unit = NULL;
|
_cleanup_free_ char *unit = NULL;
|
||||||
Session *s;
|
Session *s;
|
||||||
int r;
|
int r;
|
||||||
@ -294,38 +294,51 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
|
|||||||
|
|
||||||
r = cg_pid_get_unit(pid, &unit);
|
r = cg_pid_get_unit(pid, &unit);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return 0;
|
goto not_found;
|
||||||
|
|
||||||
s = hashmap_get(m->session_units, unit);
|
s = hashmap_get(m->session_units, unit);
|
||||||
if (!s)
|
if (!s)
|
||||||
return 0;
|
goto not_found;
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
*ret = s;
|
||||||
|
|
||||||
if (session)
|
|
||||||
*session = s;
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
not_found:
|
||||||
|
if (ret)
|
||||||
|
*ret = NULL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) {
|
int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
|
||||||
_cleanup_free_ char *unit = NULL;
|
_cleanup_free_ char *unit = NULL;
|
||||||
User *u;
|
User *u;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(user);
|
|
||||||
|
|
||||||
if (!pid_is_valid(pid))
|
if (!pid_is_valid(pid))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = cg_pid_get_slice(pid, &unit);
|
r = cg_pid_get_slice(pid, &unit);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return 0;
|
goto not_found;
|
||||||
|
|
||||||
u = hashmap_get(m->user_units, unit);
|
u = hashmap_get(m->user_units, unit);
|
||||||
if (!u)
|
if (!u)
|
||||||
return 0;
|
goto not_found;
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
*ret = u;
|
||||||
|
|
||||||
*user = u;
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
not_found:
|
||||||
|
if (ret)
|
||||||
|
*ret = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
|
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
|
||||||
|
Loading…
Reference in New Issue
Block a user