This ensures we don't erroneously assign pseudoterminals created by
terminal emulators that use utempter to register themselves in utmp when
run under a GUI session that doesn't have a TTY assigned.
return !!s;
}
+int manager_get_session_by_leader(Manager *m, const PidRef *pid, Session **ret) {
+ Session *s;
+ int r;
+
+ assert(m);
+
+ if (!pidref_is_set(pid))
+ return -EINVAL;
+
+ s = hashmap_get(m->sessions_by_leader, pid);
+ if (s) {
+ r = pidref_verify(pid);
+ if (r < 0)
+ return r;
+ }
+
+ if (ret)
+ *ret = s;
+
+ return !!s;
+}
+
int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
_cleanup_free_ char *unit = NULL;
User *u = NULL;
if (isempty(t))
continue;
- if (manager_get_session_by_pidref(m, &PIDREF_MAKE_FROM_PID(u->ut_pid), &s) <= 0)
+ if (manager_get_session_by_leader(m, &PIDREF_MAKE_FROM_PID(u->ut_pid), &s) <= 0)
continue;
if (s->tty_validity == TTY_FROM_UTMP && !streq_ptr(s->tty, t)) {
int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
int manager_get_session_by_pidref(Manager *m, const PidRef *pid, Session **ret);
+int manager_get_session_by_leader(Manager *m, const PidRef *pid, Session **ret);
bool manager_is_lid_closed(Manager *m);
bool manager_is_docked_or_external_displays(Manager *m);