summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-01-09 12:25:51 -0600
committerDan Williams <dcbw@redhat.com>2014-01-23 16:48:19 -0600
commit474b76134c63af051aa8efe18baf8ac7d5abfc81 (patch)
tree1a8101218611f4696b2b300b0d8f319ee1587eae
parent8ab8990938b995a8b49e995ff844fa359c9b4443 (diff)
downloadNetworkManager-474b76134c63af051aa8efe18baf8ac7d5abfc81.tar.gz
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.
-rw-r--r--src/nm-session-monitor-systemd.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/nm-session-monitor-systemd.c b/src/nm-session-monitor-systemd.c
index 4d8edab2d2..f195c1e775 100644
--- a/src/nm-session-monitor-systemd.c
+++ b/src/nm-session-monitor-systemd.c
@@ -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;
}