From c72d5456e2d6a6c8cefbfc16a542ae03a769397f Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sat, 20 Sep 2014 18:42:29 +0200 Subject: [PATCH 1/1] login: add public sd_session_get_desktop() API The desktop brand is stored as DESKTOP variable for sessions. It can be set arbitrarily by the session owner and identifies the desktop environment that is running on that session. --- man/pam_systemd.xml | 4 +++- man/sd_session_is_active.xml | 23 +++++++++++++++++++++++ src/libsystemd/libsystemd.sym.m4 | 7 ++++++- src/libsystemd/sd-login/sd-login.c | 19 +++++++++++++++++++ src/systemd/sd-login.h | 3 +++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/man/pam_systemd.xml b/man/pam_systemd.xml index 52dfe9df4..4df26a3f2 100644 --- a/man/pam_systemd.xml +++ b/man/pam_systemd.xml @@ -268,7 +268,9 @@ as defined by the Desktop Entry - Specification. + Specification. See + sd_session_get_desktop3 + for more details. diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml index 5006be4df..e9840669c 100644 --- a/man/sd_session_is_active.xml +++ b/man/sd_session_is_active.xml @@ -51,6 +51,7 @@ sd_session_get_service sd_session_get_type sd_session_get_class + sd_session_get_desktop sd_session_get_display sd_session_get_tty sd_session_get_vt @@ -109,6 +110,12 @@ char **class + + int sd_session_get_desktop + const char *session + char **desktop + + int sd_session_get_display const char *session @@ -218,6 +225,22 @@ free3 call after use. + sd_session_get_desktop() may + be used to determine the brand of the desktop running on + the session identified by the specified session identifier. + This field can be set freely by desktop environments and + does not follow any special formatting. However, desktops + are strongly recommended to use the same identifiers and + capitalization as for + $XDG_CURRENT_DESKTOP, as defined by + the Desktop + Entry + Specification. The returned string needs to be + freed with the libc + free3 + call after use. + sd_session_get_display() may be used to determine the X11 display of the session identified by the specified session diff --git a/src/libsystemd/libsystemd.sym.m4 b/src/libsystemd/libsystemd.sym.m4 index d1450fbb2..87da7ac02 100644 --- a/src/libsystemd/libsystemd.sym.m4 +++ b/src/libsystemd/libsystemd.sym.m4 @@ -153,6 +153,11 @@ global: sd_machine_get_ifindices; } LIBSYSTEMD_214; +LIBSYSTEMD_217 { +global: + sd_session_get_desktop; +} LIBSYSTEMD_216; + m4_ifdef(`ENABLE_KDBUS', LIBSYSTEMD_FUTURE { global: @@ -438,5 +443,5 @@ global: /* sd-path */ sd_path_home; sd_path_search; -} LIBSYSTEMD_216; +} LIBSYSTEMD_217; ) diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 95cb6ff58..c72d23ed5 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -485,6 +485,25 @@ _public_ int sd_session_get_class(const char *session, char **class) { return session_get_string(session, "CLASS", class); } +_public_ int sd_session_get_desktop(const char *session, char **desktop) { + _cleanup_free_ char *escaped = NULL; + char *t; + int r; + + assert_return(desktop, -EINVAL); + + r = session_get_string(session, "DESKTOP", &escaped); + if (r < 0) + return r; + + t = cunescape(escaped); + if (!t) + return -ENOMEM; + + *desktop = t; + return 0; +} + _public_ int sd_session_get_display(const char *session, char **display) { return session_get_string(session, "DISPLAY", display); } diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index 1eb3be30b..93af19709 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -147,6 +147,9 @@ int sd_session_get_type(const char *session, char **type); /* Determine the class of this session, i.e. one of "user", "greeter" or "lock-screen". */ int sd_session_get_class(const char *session, char **clazz); +/* Determine the desktop brand of this session, i.e. something like "GNOME", "KDE" or "SYSTEMD-CONSOLE". */ +int sd_session_get_desktop(const char *session, char **desktop); + /* Determine the X11 display of this session. */ int sd_session_get_display(const char *session, char **display); -- 2.30.2