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:
Dan Williams 2014-01-09 12:25:51 -06:00
parent 8ab8990938
commit 474b76134c

View file

@ -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;
}