mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 17:30:16 +01:00
sessions: fix return value handling for sd_uid_get_sessions() (bgo #707983)
This function returns the number of sessions found, but the return value wasn't being correctly handled for errors. Also fix the require_active parameter value to be 100% clear about what NM wants.
This commit is contained in:
parent
8ab8990938
commit
474b76134c
1 changed files with 12 additions and 10 deletions
|
|
@ -234,18 +234,19 @@ nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
|
|||
const char **out_user,
|
||||
GError **error)
|
||||
{
|
||||
int ret;
|
||||
int num_sessions;
|
||||
|
||||
if (!nm_session_uid_to_user (uid, out_user, error))
|
||||
return FALSE;
|
||||
|
||||
ret = sd_uid_get_sessions (uid, FALSE, NULL) > 0;
|
||||
if (ret < 0) {
|
||||
/* Get all sessions (including inactive ones) for the user */
|
||||
num_sessions = sd_uid_get_sessions (uid, 0, NULL);
|
||||
if (num_sessions < 0) {
|
||||
nm_log_warn (LOGD_CORE, "Failed to get systemd sessions for uid %d: %d",
|
||||
uid, ret);
|
||||
uid, num_sessions);
|
||||
return FALSE;
|
||||
}
|
||||
return ret > 0 ? TRUE : FALSE;
|
||||
return num_sessions > 0;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -253,13 +254,14 @@ nm_session_monitor_uid_active (NMSessionMonitor *monitor,
|
|||
uid_t uid,
|
||||
GError **error)
|
||||
{
|
||||
int ret;
|
||||
int num_sessions;
|
||||
|
||||
ret = sd_uid_get_sessions (uid, TRUE, NULL) > 0;
|
||||
if (ret < 0) {
|
||||
/* Get active sessions for the user */
|
||||
num_sessions = sd_uid_get_sessions (uid, 1, NULL);
|
||||
if (num_sessions < 0) {
|
||||
nm_log_warn (LOGD_CORE, "Failed to get active systemd sessions for uid %d: %d",
|
||||
uid, ret);
|
||||
uid, num_sessions);
|
||||
return FALSE;
|
||||
}
|
||||
return ret > 0 ? TRUE : FALSE;
|
||||
return num_sessions > 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue