chiark / gitweb /
login: add public sd_session_get_desktop() API
authorDavid Herrmann <dh.herrmann@gmail.com>
Sat, 20 Sep 2014 16:42:29 +0000 (18:42 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Sep 2014 12:27:02 +0000 (14:27 +0200)
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
man/sd_session_is_active.xml
src/libsystemd/libsystemd.sym.m4
src/libsystemd/sd-login/sd-login.c
src/systemd/sd-login.h

index 52dfe9df43e7a561ebf8cacc9c0c437357ad2ff4..4df26a3f2bb542ed4144013f2877f387f9585211 100644 (file)
                                 as defined by the <ulink
                                 url="http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
                                 Entry
-                                Specification</ulink>.</para></listitem>
+                                Specification</ulink>. See
+                                <citerefentry><refentrytitle>sd_session_get_desktop</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                                for more details.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index 5006be4df5421536518bc30d7dd4382098529417..e9840669c27c4efa4b0181bf5c88ba63c6a6e79c 100644 (file)
@@ -51,6 +51,7 @@
                 <refname>sd_session_get_service</refname>
                 <refname>sd_session_get_type</refname>
                 <refname>sd_session_get_class</refname>
+                <refname>sd_session_get_desktop</refname>
                 <refname>sd_session_get_display</refname>
                 <refname>sd_session_get_tty</refname>
                 <refname>sd_session_get_vt</refname>
                                 <paramdef>char **<parameter>class</parameter></paramdef>
                         </funcprototype>
 
+                        <funcprototype>
+                                <funcdef>int <function>sd_session_get_desktop</function></funcdef>
+                                <paramdef>const char *<parameter>session</parameter></paramdef>
+                                <paramdef>char **<parameter>desktop</parameter></paramdef>
+                        </funcprototype>
+
                         <funcprototype>
                                 <funcdef>int <function>sd_session_get_display</function></funcdef>
                                 <paramdef>const char *<parameter>session</parameter></paramdef>
                 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 call after use.</para>
 
+                <para><function>sd_session_get_desktop()</function> 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
+                <varname>$XDG_CURRENT_DESKTOP</varname>, as defined by
+                the <ulink
+                url="http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
+                Entry
+                Specification</ulink>. The returned string needs to be
+                freed with the libc
+                <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                call after use.</para>
+
                 <para><function>sd_session_get_display()</function>
                 may be used to determine the X11 display of the
                 session identified by the specified session
index d1450fbb26f0abed567b8d1fd4b974824880fc7f..87da7ac021c35f3368b89996f5a8209528f7a7f0 100644 (file)
@@ -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;
 )
index 95cb6ff5812c1dd95119377d24ac8e7839b982b2..c72d23ed5342f2032a85c438ca7741897262d282 100644 (file)
@@ -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);
 }
index 1eb3be30b53f454a5527fe174e314e942040ed1f..93af19709b0dd3294655678d9ac03989c8d7e139 100644 (file)
@@ -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);