diff options
author | Robert Nagy <robert@openbsd.org> | 2022-11-10 11:37:29 +0100 |
---|---|---|
committer | Robert Nagy <robert@openbsd.org> | 2022-11-10 11:37:29 +0100 |
commit | 74695630307785e571599a5c93f4a3bda129a17a (patch) | |
tree | 31e110a811c242095092405934b28c636f00e7f3 | |
parent | c4e68a271d1ec922a3339385e3569f32040b710b (diff) | |
download | ConsoleKit2-74695630307785e571599a5c93f4a3bda129a17a.tar.gz |
add sd_get_sessions()
-rw-r--r-- | libconsolekit/libconsolekit.c | 57 | ||||
-rw-r--r-- | libconsolekit/libconsolekit.h | 5 | ||||
-rw-r--r-- | libconsolekit/sd-compat.c | 23 | ||||
-rw-r--r-- | libconsolekit/sd-login.h | 2 |
4 files changed, 87 insertions, 0 deletions
diff --git a/libconsolekit/libconsolekit.c b/libconsolekit/libconsolekit.c index a86b353..f70474e 100644 --- a/libconsolekit/libconsolekit.c +++ b/libconsolekit/libconsolekit.c @@ -321,6 +321,63 @@ lib_consolekit_uid_get_sessions (LibConsoleKit *ck, } /** + * lib_consolekit_get_sessions: + **/ +gint +lib_consolekit_get_sessions (LibConsoleKit *ck, + gchar ***sessions, + GError **error) +{ + GDBusProxy *manager_proxy = NULL; + GVariant *variant = NULL; + + if (ck == NULL) { + g_set_error (error, + CONSOLEKIT_ERROR, + CONSOLEKIT_ERROR_INVALID_INPUT, + "Invalid LibConsoleKit"); + return -1; + } + + /* connect to the ConsoleKit manager */ + manager_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + CK_NAME, + CK_MANAGER_PATH, + CK_MANAGER_NAME, + NULL, + error); + + /* failed to connect */ + if (manager_proxy == NULL) { + return FALSE; + } + + variant = g_dbus_proxy_call_sync (manager_proxy, + "GetSessions", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + error); + + /* We're done with the seat proxy */ + g_clear_object(&manager_proxy); + + if (variant == NULL) { + return -1; + } + + g_variant_get (variant, "(^ao)", sessions); + + g_variant_unref (variant); + variant = NULL; + + return g_strv_length (*sessions); +} + +/** * lib_consolekit_seat_get_sessions: * @ck : A #LibConsoleKit * @seat : The seat to query diff --git a/libconsolekit/libconsolekit.h b/libconsolekit/libconsolekit.h index 3619898..c435215 100644 --- a/libconsolekit/libconsolekit.h +++ b/libconsolekit/libconsolekit.h @@ -148,5 +148,10 @@ lib_consolekit_uid_get_sessions (LibConsoleKit *ck, gchar ***sessions, GError **error); +gint +lib_consolekit_get_sessions (LibConsoleKit *ck, + gchar ***sessions, + GError **error); + #endif /* LIB_CONSOLEKIT_H_ */ diff --git a/libconsolekit/sd-compat.c b/libconsolekit/sd-compat.c index a5d60e5..a5ed457 100644 --- a/libconsolekit/sd-compat.c +++ b/libconsolekit/sd-compat.c @@ -165,3 +165,26 @@ sd_seat_can_multi_session(const char *seat) return can_activate; } + +int +sd_get_sessions(char ***sessions) +{ + LibConsoleKit *ck = NULL; + GError *error = NULL; + int ret = 0; + + ck = lib_consolekit_new (); + + ret = lib_consolekit_get_sessions (ck, sessions, &error); + if (error) { + g_warning ("Unable to get sessions: %s", + error ? error->message : ""); + g_error_free (error); + g_object_unref (ck); + return -ENXIO; + } + + g_object_unref (ck); + + return ret; +} diff --git a/libconsolekit/sd-login.h b/libconsolekit/sd-login.h index 8312d7b..bbaca76 100644 --- a/libconsolekit/sd-login.h +++ b/libconsolekit/sd-login.h @@ -8,3 +8,5 @@ int sd_session_get_uid(const char *session, uid_t *uid); int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions); int sd_seat_can_multi_session(const char *seat); + +int sd_get_sessions(char ***sessions); |