Blame SOURCES/kde-workspace-4.11.1-kdm-logind-multiseat.patch

ff3475
diff -up kde-workspace-4.10.90/CMakeLists.txt.kdm_logind kde-workspace-4.10.90/CMakeLists.txt
ff3475
--- kde-workspace-4.10.90/CMakeLists.txt.kdm_logind	2013-06-27 16:27:30.199895076 -0500
ff3475
+++ kde-workspace-4.10.90/CMakeLists.txt	2013-06-27 16:30:25.167008304 -0500
ff3475
@@ -128,6 +128,13 @@ if(Q_WS_X11)
ff3475
   endif()
652846
 endif(Q_WS_X11)
652846
 
652846
+macro_optional_find_package(Systemd)
ff3475
+set_package_properties(Systemd PROPERTIES DESCRIPTION "Init and service manager for Linux"
ff3475
+                       URL "http://www.freedesktop.org/wiki/Software/systemd"
ff3475
+                       TYPE OPTIONAL
ff3475
+                       PURPOSE "Provides automatic multi-seat, session and power management features"
ff3475
+                      )
652846
+
ff3475
 macro_optional_find_package(GLIB2 2.0)
ff3475
 set_package_properties(GLIB2 PROPERTIES DESCRIPTION "Low-level core library for data structure handling, portability wrappers, etc."
ff3475
                        URL "http://www.gtk.org"
ff3475
diff -up kde-workspace-4.10.90/cmake/modules/CMakeLists.txt.kdm_logind kde-workspace-4.10.90/cmake/modules/CMakeLists.txt
ff3475
--- kde-workspace-4.10.90/cmake/modules/CMakeLists.txt.kdm_logind	2013-06-10 13:51:11.000000000 -0500
ff3475
+++ kde-workspace-4.10.90/cmake/modules/CMakeLists.txt	2013-06-27 16:27:30.199895076 -0500
ff3475
@@ -8,6 +8,7 @@ set(cmakeFiles FindCkConnector.cmake
652846
                FindOpenGLES.cmake
652846
                FindPAM.cmake
652846
                FindSensors.cmake
652846
+               FindSystemd.cmake
652846
                PkgConfigGetVar.cmake
652846
                UnixAuth.cmake )
652846
 
ff3475
diff -up kde-workspace-4.10.90/cmake/modules/FindSystemd.cmake.kdm_logind kde-workspace-4.10.90/cmake/modules/FindSystemd.cmake
ff3475
--- kde-workspace-4.10.90/cmake/modules/FindSystemd.cmake.kdm_logind	2013-06-27 16:27:30.200895065 -0500
ff3475
+++ kde-workspace-4.10.90/cmake/modules/FindSystemd.cmake	2013-06-27 16:27:30.200895065 -0500
652846
@@ -0,0 +1,39 @@
652846
+# Finds systemd and its libraries
652846
+# Not a huge module but sufficient for now
652846
+# Uses the same semantics as pkg_check_modules, i.e. ${LIB}{_FOUND,_INCLUDE_DIR,_LIBRARIES}
652846
+# where ${LIB} can be one of the following:
652846
+#     LIBSYSTEMD_JOURNAL, SYSTEMD, LIBSYSTEMD_DAEMON, LIBSYSTEMD_LOGIN, LIBSYSTEMD_ID128
652846
+#
652846
+# Copyright: Red Hat, Inc. 2013
652846
+# Author: Martin Briza <mbriza@redhat.com>
652846
+#
652846
+# Distributed under the BSD license. See COPYING-CMAKE-SCRIPTS for details.
652846
+
652846
+#defining any of these disables systemd support
652846
+if (NOT LIBSYSTEMD_JOURNAL_FOUND AND
652846
+    NOT SYSTEMD_FOUND AND
652846
+    NOT LIBSYSTEMD_DAEMON_FOUND AND
652846
+    NOT LIBSYSTEMD_LOGIN_FOUND AND
652846
+    NOT LIBSYSTEMD_ID128_FOUND)
652846
+find_package(PkgConfig)
652846
+if (PKG_CONFIG_FOUND)
652846
+    pkg_check_modules(LIBSYSTEMD_JOURNAL QUIET "libsystemd-journal")
652846
+    pkg_check_modules(SYSTEMD QUIET "systemd")
652846
+    pkg_check_modules(LIBSYSTEMD_DAEMON QUIET "libsystemd-daemon")
652846
+    pkg_check_modules(LIBSYSTEMD_LOGIN QUIET "libsystemd-login")
652846
+    pkg_check_modules(LIBSYSTEMD_ID128 QUIET "libsystemd-id128")
652846
+endif (PKG_CONFIG_FOUND)
652846
+
652846
+if (SYSTEMD_FOUND)
652846
+    message(STATUS "Found systemd")
652846
+endif(SYSTEMD_FOUND)
652846
+
652846
+mark_as_advanced(LIBSYSTEMD_JOURNAL_FOUND       SYSTEMD_FOUND       LIBSYSTEMD_DAEMON_FOUND       LIBSYSTEMD_LOGIN_FOUND       LIBSYSTEMD_ID128_FOUND)
652846
+mark_as_advanced(LIBSYSTEMD_JOURNAL_INCLUDE_DIR SYSTEMD_INCLUDE_DIR LIBSYSTEMD_DAEMON_INCLUDE_DIR LIBSYSTEMD_LOGIN_INCLUDE_DIR LIBSYSTEMD_ID128_INCLUDE_DIR)
652846
+mark_as_advanced(LIBSYSTEMD_JOURNAL_LIBRARIES   SYSTEMD_LIBRARIES   LIBSYSTEMD_DAEMON_LIBRARIES   LIBSYSTEMD_LOGIN_LIBRARIES   LIBSYSTEMD_ID128_LIBRARIES)
652846
+
652846
+endif (NOT LIBSYSTEMD_JOURNAL_FOUND AND
652846
+       NOT SYSTEMD_FOUND AND
652846
+       NOT LIBSYSTEMD_DAEMON_FOUND AND
652846
+       NOT LIBSYSTEMD_LOGIN_FOUND AND
652846
+       NOT LIBSYSTEMD_ID128_FOUND)
ff3475
diff -up kde-workspace-4.10.90/kdm/backend/CMakeLists.txt.kdm_logind kde-workspace-4.10.90/kdm/backend/CMakeLists.txt
ff3475
--- kde-workspace-4.10.90/kdm/backend/CMakeLists.txt.kdm_logind	2013-05-28 13:38:21.000000000 -0500
ff3475
+++ kde-workspace-4.10.90/kdm/backend/CMakeLists.txt	2013-06-27 16:27:30.201895054 -0500
ff3475
@@ -45,6 +45,10 @@ if (SECURE_RPC)
ff3475
 		rpcauth.c
ff3475
 	)
ff3475
 endif (SECURE_RPC)
ff3475
+if(LIBSYSTEMD_LOGIN_FOUND AND LIBSYSTEMD_DAEMON_FOUND)
ff3475
+    add_definitions( -DWITH_SYSTEMD=1 )
ff3475
+    set(KDM_SYSTEMD_LIBRARIES ${LIBSYSTEMD_DAEMON_LIBRARIES} ${LIBSYSTEMD_LOGIN_LIBRARIES} )
ff3475
+endif(LIBSYSTEMD_LOGIN_FOUND AND LIBSYSTEMD_DAEMON_FOUND)
ff3475
 macro_add_file_dependencies(dm.h ${confci})
ff3475
 macro_add_file_dependencies(error.c ${CMAKE_CURRENT_SOURCE_DIR}/printf.c)
ff3475
 kde4_add_executable(kdm NOGUI ${kdm_SRCS})
ff3475
@@ -61,6 +65,7 @@ target_link_libraries( kdm
ff3475
 	${NSL_LIBRARIES}
ff3475
 	${RESOLV_LIBRARIES}
ff3475
 	${SOCKET_LIBRARIES}
ff3475
+	${KDM_SYSTEMD_LIBRARIES}
ff3475
 )
ff3475
 if (CKCONNECTOR_FOUND)
ff3475
 	include_directories(${CKCONNECTOR_INCLUDE_DIR} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
ff3475
diff -up kde-workspace-4.10.90/kdm/backend/dm.c.kdm_logind kde-workspace-4.10.90/kdm/backend/dm.c
ff3475
--- kde-workspace-4.10.90/kdm/backend/dm.c.kdm_logind	2013-06-27 16:27:30.184895241 -0500
ff3475
+++ kde-workspace-4.10.90/kdm/backend/dm.c	2013-06-27 16:27:30.201895054 -0500
652846
@@ -50,6 +50,23 @@ from the copyright holder.
652846
 # include <sys/vt.h>
652846
 #endif
652846
 
652846
+#ifdef WITH_SYSTEMD
652846
+# include <systemd/sd-login.h>
652846
+# include <systemd/sd-daemon.h>
652846
+
652846
+#define SYSTEMD_FAILURE_LIMIT 25
652846
+
652846
+ static int systemdMonitorInit(void);
652846
+ static void systemdMonitorDeinit();
652846
+ static int systemdStartDisplay(char *);
652846
+ static void systemdCheckAdded(char **);
652846
+ static void systemdCheckRemoved(char **);
652846
+ static void systemdHandleChange();
652846
+
652846
+ sd_login_monitor *systemd_monitor = NULL;
652846
+ int systemd_monitor_fd = -1;
652846
+#endif
652846
+
652846
 static void sigHandler(int n);
652846
 static int scanConfigs(int force);
652846
 static void startDisplay(struct display *d);
652846
@@ -308,7 +325,16 @@ main(int argc, char **argv)
652846
 #ifdef XDMCP
652846
     updateListenSockets();
652846
 #endif
652846
+
652846
+#ifdef WITH_SYSTEMD
652846
+    if (systemdMonitorInit())
652846
+        systemdHandleChange();
652846
+#endif
652846
+
652846
     mainLoop();
652846
+#ifdef WITH_SYSTEMD
652846
+    systemdMonitorDeinit();
652846
+#endif
652846
     closeCtrl(0);
652846
     if (sdRec.how) {
652846
         int pid;
652846
@@ -1280,6 +1306,14 @@ mainLoop(void)
652846
                 }
652846
                 continue;
652846
             }
652846
+                logError("STARTING");
652846
+#ifdef WITH_SYSTEMD
652846
+            if (systemd_monitor_fd >= 0 && FD_ISSET(systemd_monitor_fd, &reads)) {
652846
+                systemdHandleChange();
652846
+                sd_login_monitor_flush(systemd_monitor);
652846
+                continue;
652846
+            }
652846
+#endif
652846
 #ifdef XDMCP
652846
             if (processListenSockets(&reads))
652846
                 continue;
652846
@@ -1304,6 +1338,151 @@ mainLoop(void)
652846
     }
652846
 }
652846
 
652846
+#ifdef WITH_SYSTEMD
652846
+static int
652846
+systemdMonitorInit(void)
652846
+{
652846
+    if (sd_booted() <= 0) {
652846
+        logError("Didn't boot with systemd, automatic multiseat won't be enabled\n");
652846
+        return False;
652846
+    }
652846
+
652846
+    int check = sd_login_monitor_new("seat", &systemd_monitor);
652846
+    if (check < 0) {
652846
+        logError("Can't get systemd monitor: %d, automatic multiseat won't be enabled\n", check);
652846
+        return False;
652846
+    }
652846
+
652846
+    systemd_monitor_fd = sd_login_monitor_get_fd(systemd_monitor);
652846
+    if (systemd_monitor_fd < 0) {
652846
+        logError("Can't retrieve file descriptor from the systemd monitor: %d, automatic multiseat won't be enabled\n", systemd_monitor_fd);
652846
+        sd_login_monitor_unref(systemd_monitor);
652846
+        systemd_monitor_fd = -1;
652846
+        return False;
652846
+    }
652846
+
652846
+    registerInput(systemd_monitor_fd);
652846
+    return True;
652846
+}
652846
+
652846
+static void
652846
+systemdMonitorDeinit(void)
652846
+{
652846
+    if (systemd_monitor) {
652846
+        sd_login_monitor_unref(systemd_monitor);
652846
+    }
652846
+    systemd_monitor_fd = -1;
652846
+}
652846
+
652846
+static int
652846
+systemdStartDisplay(char *seat)
652846
+{
652846
+    struct display *link = NULL;
652846
+    for (link = displays; link; link = link-> next) {
652846
+        if (link->status == reserve)
652846
+            break;
652846
+    }
652846
+    if (!link) {
652846
+        logError("There's not enough reserve displays for all your seats/sessions");
652846
+        return False;
652846
+    }
652846
+    if (!strDup((&link->systemd_seat), seat)) {
652846
+        return False;
652846
+    }
652846
+#ifdef HAVE_VTS
652846
+    link->serverVT = 0;
652846
+#endif
652846
+    link->status = notRunning;
652846
+    link->stillThere = True;
652846
+    link->authorize = True;
652846
+    link->displayType = dLocal | dPermanent;
652846
+    link->reqSrvVT = -1;
652846
+    link->serverPid = -1;
652846
+    return True;
652846
+}
652846
+
652846
+static void
652846
+systemdCheckAdded(char **seat_names) 
652846
+{
652846
+    char **iter_name;
652846
+    struct display *link;
652846
+    for (iter_name = seat_names; *iter_name; iter_name++) {
652846
+        if (strcmp(*iter_name, "seat0") == 0)
652846
+            continue; /* ignore the main seat */
652846
+        int can_graphical = sd_seat_can_graphical(*iter_name);
652846
+        for (link = displays; link; link = link->next) {
652846
+            if (!link->systemd_seat)
652846
+                continue;
652846
+            /* see if the can_graphical property didn't change */
ff3475
+            if (strcmp(*iter_name, link->systemd_seat) == 0) {
652846
+                if (!can_graphical) {
652846
+                    free(link->systemd_seat);
652846
+                    link->systemd_seat = NULL;
652846
+                    rStopDisplay(link, DS_RESERVE);
652846
+                }
652846
+                break;
652846
+            }
652846
+        }
652846
+        /* the display wasn't found */
652846
+        if (!link) {
652846
+            if (can_graphical) {
652846
+                /* if starting the display failed, skip this round until the next change */
652846
+                if (!systemdStartDisplay(*iter_name))
652846
+                    break;
652846
+            }
652846
+        }
652846
+    }
652846
+}
652846
+
652846
+static void
652846
+systemdCheckRemoved(char **seat_names)
652846
+{
652846
+    char **iter_name;
652846
+    struct display *link;
652846
+    for (link = displays; link; link = link->next) {
652846
+        for (iter_name = seat_names; *iter_name; iter_name++) {
652846
+            if (strcmp(*iter_name, "seat0") == 0)
652846
+                continue; /* ignore the main seat */
652846
+            if (link->systemd_seat && strcmp(*iter_name, link->systemd_seat) == 0)
652846
+                break;
652846
+        }
652846
+        if (!(*iter_name) && link->systemd_seat) { /* was not found, stop this one */
652846
+            free(link->systemd_seat);
652846
+            link->systemd_seat = NULL;
652846
+            rStopDisplay(link, DS_RESERVE);
652846
+        }
652846
+    }
652846
+}
652846
+
652846
+static void
652846
+systemdHandleChange(void)
652846
+{
652846
+    static int failures = 0;
652846
+    char **seat_names;
652846
+    char **iter_name;
652846
+    int check;
652846
+    if ((check = sd_get_seats(&seat_names)) < 0) {
652846
+        logError("Can't obtain systemd seats, error %d\n", -check);
652846
+        failures++;
652846
+        if (failures >= SYSTEMD_FAILURE_LIMIT) {
652846
+            logError("%u failed calls to sd_get_seats, disabling systemd multi-seat support\n", SYSTEMD_FAILURE_LIMIT);
652846
+            systemdMonitorDeinit();
652846
+        }
652846
+        return;
652846
+    }
652846
+
652846
+    if (!check)
652846
+        return;
652846
+
652846
+    systemdCheckAdded(seat_names);
652846
+    systemdCheckRemoved(seat_names);
652846
+
652846
+    for (iter_name = seat_names; *iter_name; iter_name++)
652846
+        free(*iter_name);
652846
+    free(seat_names);
652846
+}
652846
+#endif
652846
+
652846
 static void
652846
 checkDisplayStatus(struct display *d)
652846
 {
ff3475
diff -up kde-workspace-4.10.90/kdm/backend/dm.h.kdm_logind kde-workspace-4.10.90/kdm/backend/dm.h
ff3475
--- kde-workspace-4.10.90/kdm/backend/dm.h.kdm_logind	2013-06-27 16:27:30.184895241 -0500
ff3475
+++ kde-workspace-4.10.90/kdm/backend/dm.h	2013-06-27 16:27:30.201895054 -0500
652846
@@ -306,6 +306,9 @@ struct display {
652846
     char *greeterAuthFile;      /* file to store authorization for greeter in */
652846
     
ff3475
     int plymouth_vt;            /* Plymouth's VT nr */
652846
+#ifdef WITH_SYSTEMD
652846
+    char *systemd_seat;
652846
+#endif
652846
 };
652846
 
652846
 #define d_location   1
ff3475
diff -up kde-workspace-4.10.90/kdm/backend/server.c.kdm_logind kde-workspace-4.10.90/kdm/backend/server.c
ff3475
--- kde-workspace-4.10.90/kdm/backend/server.c.kdm_logind	2013-06-27 16:27:30.184895241 -0500
ff3475
+++ kde-workspace-4.10.90/kdm/backend/server.c	2013-06-27 16:27:30.201895054 -0500
ff3475
@@ -43,6 +43,7 @@ from the copyright holder.
ff3475
 #include <stdio.h>
ff3475
 #include <signal.h>
ff3475
 
ff3475
+#define SYSTEMD_X_WRAPPER "/lib/systemd/systemd-multi-seat-x"
ff3475
 
ff3475
 struct display *startingServer;
ff3475
 time_t serverTimeout = TO_INF;
ff3475
@@ -55,9 +56,18 @@ prepareServerArgv(struct display *d, con
ff3475
     char vtstr[8];
ff3475
 #endif
ff3475
 
ff3475
-    if (!(argv = parseArgs(0, d->serverCmd)) ||
ff3475
-        !(argv = addStrArr(argv, d->name, -1)))
ff3475
+#if WITH_SYSTEMD
ff3475
+    FILE *tmpFile = NULL;
ff3475
+    if ((tmpFile = fopen(SYSTEMD_X_WRAPPER, "rb")) != NULL && fclose(tmpFile) == 0) {
ff3475
+        if (!(argv = parseArgs(0, SYSTEMD_X_WRAPPER)) || !(argv = addStrArr(argv, d->name, -1))) {
ff3475
+            exit(47);
ff3475
+        }
ff3475
+    }
ff3475
+    else
ff3475
+#endif
ff3475
+    if (!(argv = parseArgs(0, d->serverCmd)) || !(argv = addStrArr(argv, d->name, -1))) {
ff3475
         exit(47);
ff3475
+    }
ff3475
 #ifdef HAVE_VTS
ff3475
     if (d->serverVT &&
ff3475
         !(argv = addStrArr(argv, vtstr,
ff3475
@@ -70,6 +80,25 @@ prepareServerArgv(struct display *d, con
652846
     if (!changeUser(d->serverUID, d->authFile))
652846
         exit(47);
652846
 
652846
+#ifdef WITH_SYSTEMD
652846
+    if (d->systemd_seat) {
652846
+        if (!(argv = parseArgs(argv, "-seat")))
652846
+            exit(47);
652846
+        if (!(argv = parseArgs(argv, d->systemd_seat)))
652846
+            exit(47);
ff3475
+        if (!(argv = parseArgs(argv, "-layout")))
ff3475
+            exit(47);
ff3475
+        if (!(argv = parseArgs(argv, d->systemd_seat)))
ff3475
+            exit(47);
652846
+    }
652846
+    else {
652846
+        if (!(argv = parseArgs(argv, "-seat")))
652846
+            exit(47);
652846
+        if (!(argv = parseArgs(argv, "seat0")))
652846
+            exit(47);
652846
+    }
652846
+#endif
652846
+
652846
     return argv;
652846
 }
652846
 
ff3475
--- kde-workspace-4.10.2/kdm/backend/client.c.kdm_logind
ff3475
+++ kde-workspace-4.10.2/kdm/backend/client.c
ff3475
@@ -1460,6 +1460,14 @@ startClient(volatile int *pid)
ff3475
 #endif
ff3475
     userEnviron = inheritEnv(env, envvars);
ff3475
     env = systemEnv(0, curuser);
ff3475
+#ifdef WITH_SYSTEMD
ff3475
+    if (td->systemd_seat) {
ff3475
+        char *envbuf;
ff3475
+        ASPrintf(&envbuf, "XDG_SEAT=%s", td->systemd_seat);
ff3475
+        pam_putenv(pamh, envbuf);
ff3475
+        env = setEnv(env, "XDG_SEAT", td->systemd_seat);
ff3475
+    }
ff3475
+#endif
ff3475
     systemEnviron = setEnv(env, "HOME", p->pw_dir);
ff3475
     debug("user environment:\n%[|''>'\n's"
ff3475
           "system environment:\n%[|''>'\n's"
ff3475
--- kde-workspace-4.10.2/kdm/backend/session.c.kdm_logind
ff3475
+++ kde-workspace-4.10.2/kdm/backend/session.c
ff3475
@@ -437,6 +437,10 @@ openGreeter()
ff3475
 
ff3475
     grttalk.pipe = &grtproc.pipe;
ff3475
     env = systemEnv(dupEnv(), 0);
ff3475
+#ifdef WITH_SYSTEMD
ff3475
+    if (td->systemd_seat)
ff3475
+        env = setEnv(env, "XDG_SEAT", td->systemd_seat);
ff3475
+#endif
ff3475
     if (gOpen(&grtproc, (char **)0, "_greet", env, name,
ff3475
               greeterUID, td->greeterAuthFile, &td->gpipe))
ff3475
         sessionExit(EX_UNMANAGE_DPY);