diff options
Diffstat (limited to 'src/nm-session-monitor-systemd.c')
| -rw-r--r-- | src/nm-session-monitor-systemd.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/nm-session-monitor-systemd.c b/src/nm-session-monitor-systemd.c index f9fb075d..f195c1e7 100644 --- a/src/nm-session-monitor-systemd.c +++ b/src/nm-session-monitor-systemd.c @@ -193,11 +193,8 @@ nm_session_monitor_get (void) { static NMSessionMonitor *singleton = NULL; - if (singleton) - return g_object_ref (singleton); - - singleton = NM_SESSION_MONITOR (g_object_new (NM_TYPE_SESSION_MONITOR, NULL)); - g_assert (singleton); + if (!singleton) + singleton = g_object_new (NM_TYPE_SESSION_MONITOR, NULL); return singleton; } @@ -237,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 @@ -256,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; } |