:: Re: [devuan-dev] Libseat support fo…
Góra strony
Delete this message
Reply to this message
Autor: Adam Sampson
Data:  
Dla: devuan developers internal list
CC: dng
Temat: Re: [devuan-dev] Libseat support for xorg
Hi Mark,

On Mon, Dec 19, 2022 at 12:00:22PM +0000, Mark Hindley wrote:
> I have merged your suggestions with the changes I had queued and
> pushed[1]. Let me know if there is anything I have missed.


Looks good! I ran the modified files through the x-indent script
(https://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh) which
pulled out a few more stylistic things (watch for tabs in particular).
You can also get rid of a couple more #ifdefs now you've added the stubs
to seatd-libseat.h. Patches attached.

xorg-server 21.1.6 came out this morning, so I've just tested that it
works OK on top of that too.

Thanks very much,

-- 
Adam Sampson <ats@???>                         <http://offog.org/>

>From 101ce47e12fde0e9e50f28eca959bfbee9fb4e29 Mon Sep 17 00:00:00 2001
From: Adam Sampson <ats@???>
Date: Mon, 19 Dec 2022 14:07:07 +0000
Subject: [PATCH 1/2] More style fixes.

---
 configure.ac                                |  8 +--
 hw/xfree86/common/xf86Init.c                |  2 +-
 hw/xfree86/common/xf86Xinput.c              |  5 +-
 hw/xfree86/os-support/linux/lnx_platform.c  | 17 ++---
 hw/xfree86/os-support/linux/seatd-libseat.c | 69 ++++++++++++---------
 5 files changed, 56 insertions(+), 45 deletions(-)


diff --git a/configure.ac b/configure.ac
index 75b207c71..dff5b6377 100644
--- a/configure.ac
+++ b/configure.ac
@@ -892,12 +892,12 @@ if test "x$SEATD_LIBSEAT" = xauto; then
         fi
 fi
 if test "x$SEATD_LIBSEAT" = xyes; then
-    if ! test "x$CONFIG_UDEV" = xyes ; then
-        AC_MSG_ERROR([seatd-libseat is only supported in combination with udev configuration.])
+        if ! test "x$CONFIG_UDEV" = xyes ; then
+                AC_MSG_ERROR([seatd-libseat is only supported in combination with udev configuration.])
         fi
-    REQUIRED_LIBS="$REQUIRED_LIBS libseat"
+        REQUIRED_LIBS="$REQUIRED_LIBS libseat"
         AC_DEFINE(SEATD_LIBSEAT, 1, [Enable libseat integration])
-    SYSTEMD_LOGIND=no
+        SYSTEMD_LOGIND=no
 fi
 AM_CONDITIONAL(SEATD_LIBSEAT, [test "x$SEATD_LIBSEAT" = xyes])


diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 55f1ec13d..6c3668229 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -341,7 +341,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)

         dbus_core_init();
 #ifdef SEATD_LIBSEAT
-    seatd_libseat_init();
+        seatd_libseat_init();
 #endif
         systemd_logind_init();


diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 95cea7cf7..51b65d3cc 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -943,10 +943,11 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
     if (path && pInfo->major == 0 && pInfo->minor == 0)
         xf86stat(path, &pInfo->major, &pInfo->minor);


-    if (path && (drv->capabilities & XI86_DRV_CAP_SERVER_FD)){
-    seatd_libseat_open_device(pInfo);
+    if (path && (drv->capabilities & XI86_DRV_CAP_SERVER_FD)) {
+        seatd_libseat_open_device(pInfo);
         int fd = systemd_logind_take_fd(pInfo->major, pInfo->minor,
                                         path, &paused);
+
         if (fd != -1) {
             if (paused) {
                 /* Put on new_input_devices list for delayed probe */
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
index dc37e5428..5832b1eaf 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -31,10 +31,11 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)


     LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath);


-    fd = seatd_libseat_open_graphics( path );
+    fd = seatd_libseat_open_graphics(path);
     if (fd == -1) {
-    LogMessage(X_INFO, "seatd_libseat cannot open graphics\n");
-    } else {
+        LogMessage(X_INFO, "seatd_libseat cannot open graphics\n");
+    }
+    else {
         attribs->fd = fd;
         server_fd = TRUE;
     }
@@ -50,12 +51,12 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
         server_fd = TRUE;
     }
     if (fd == -1) {
-    // Try opening the path directly
+        /* try opening the path directly */
         fd = open(path, O_RDWR | O_CLOEXEC, 0);
-    if (fd == -1) {
-        xf86Msg(X_ERROR, "cannot open %s\n", path);
-        return FALSE;
-    }
+        if (fd == -1) {
+            xf86Msg(X_ERROR, "cannot open %s\n", path);
+            return FALSE;
+        }
     }


     /* for a delayed probe we've already added the device */
diff --git a/hw/xfree86/os-support/linux/seatd-libseat.c b/hw/xfree86/os-support/linux/seatd-libseat.c
index 510a4b33f..bdc791b06 100644
--- a/hw/xfree86/os-support/linux/seatd-libseat.c
+++ b/hw/xfree86/os-support/linux/seatd-libseat.c
@@ -44,7 +44,7 @@
 #include "globals.h"
 #include "seatd-libseat.h"


-// ============ libseat client adapter ======================
+/* ===== libseat client adapter ===== */

 struct libseat_info {
     char *session;
@@ -65,7 +65,7 @@ static struct libseat_info seat_info;
  * may have had their functionality blocked or revoked.
  */
 static void
-enable_seat(struct libseat *seat,void *userdata)
+enable_seat(struct libseat *seat, void *userdata)
 {
     (void) userdata;
     LogMessage(X_INFO, "seatd_libseat enable\n");
@@ -90,7 +90,7 @@ disable_seat(struct libseat *seat, void *userdata)
     seat_info.vt_active = FALSE;
     xf86VTLeave();
     if (libseat_disable_seat(seat)) {
-    LogMessage(X_ERROR, "seatd_libseat disable failed: %d\n", errno);
+        LogMessage(X_ERROR, "seatd_libseat disable failed: %d\n", errno);
     }
 }


@@ -109,13 +109,13 @@ libseat_seat_listener client_callbacks = {
 static Bool
 libseat_active(void)
 {
-    if (! seat_info.client) {
-    LogMessage(X_ERROR, "seatd_libseat not initialised!\n");
+    if (!seat_info.client) {
+        LogMessage(X_ERROR, "seatd_libseat not initialised!\n");
         return FALSE;
     }
-    if (! seat_info.active) {
-    LogMessage(X_ERROR, "seatd_libseat not active\n");
-    return FALSE;
+    if (!seat_info.active) {
+        LogMessage(X_ERROR, "seatd_libseat not active\n");
+        return FALSE;
     }
     return TRUE;
 }
@@ -127,6 +127,7 @@ static int
 libseat_handle_events(int timeout)
 {
     int ret;
+
     while ((ret = libseat_dispatch(seat_info.client, timeout)) > 0)
         LogMessage(X_INFO, "seatd_libseat handled %i events\n", ret);
     if (ret == -1) {
@@ -159,14 +160,14 @@ log_libseat(enum libseat_log_level level, const char *fmt, va_list args)
         xmt = X_ERROR;
         break;
     default:
-         xmt = X_DEBUG;
+        xmt = X_DEBUG;
     }
     LogVMessageVerb(xmt, 0, xfmt, args);


     free(xfmt);
 }


-// ============== seatd-libseat.h API functions =============
+/* ===== seatd-libseat.h API functions ===== */

 /*
  * Initialise the libseat client.
@@ -183,14 +184,14 @@ seatd_libseat_init(void)
     libseat_set_log_handler(log_libseat);
     LogMessage(X_INFO, "seatd_libseat init\n");
     if (libseat_active()) {
-    LogMessage(X_ERROR, "seatd_libseat already initialised\n");
-    return -EPERM;
+        LogMessage(X_ERROR, "seatd_libseat already initialised\n");
+        return -EPERM;
     }
     seat_info.graphics_id = -1;
     seat_info.client = libseat_open_seat(&client_callbacks, NULL);
-    if (! seat_info.client) {
-    LogMessage(X_ERROR, "Cannot set up seatd_libseat client\n");
-    return -EPIPE;
+    if (!seat_info.client) {
+        LogMessage(X_ERROR, "Cannot set up seatd_libseat client\n");
+        return -EPIPE;
     }
     if (libseat_handle_events(100) < 0) {
         libseat_close_seat(seat_info.client);
@@ -227,15 +228,19 @@ int
 seatd_libseat_open_graphics(const char *path)
 {
     int fd, id;
+
     LogMessage(X_INFO, "seatd_libseat try open graphics %s\n", path);
-    if (! libseat_active()) {
-    return -EPERM;
+    if (!libseat_active()) {
+        return -EPERM;
     }
     if ((id = libseat_open_device(seat_info.client, path, &fd)) == -1) {
-    fd = -errno;
-        LogMessage(X_ERROR, "seatd_libseat open graphics %s (%d) failed: %d\n", path, id, fd);
-    } else {
-        LogMessage(X_INFO, "seatd_libseat opened graphics: %s (%d:%d)\n", path, id, fd);
+        fd = -errno;
+        LogMessage(X_ERROR, "seatd_libseat open graphics %s (%d) failed: %d\n",
+                   path, id, fd);
+    }
+    else {
+        LogMessage(X_INFO, "seatd_libseat opened graphics: %s (%d:%d)\n",
+                   path, id, fd);
     }
     seat_info.graphics_id = id;
     return fd;
@@ -252,17 +257,20 @@ seatd_libseat_open_device(InputInfoPtr p)
 {
     int id, fd;
     char *path = xf86CheckStrOption(p->options, "Device", NULL);
+
     LogMessage(X_INFO, "seatd_libseat try open %s\n", path);
-    if (! libseat_active()) {
-    return;
+    if (!libseat_active()) {
+        return;
     }
     if ((id = libseat_open_device(seat_info.client, path, &fd)) == -1) {
-    fd = -errno;
-        LogMessage(X_ERROR, "seatd_libseat open %s (%d) failed: %d\n", path, id,  fd);
-    } else {
+        fd = -errno;
+        LogMessage(X_ERROR, "seatd_libseat open %s (%d) failed: %d\n",
+                   path, id, fd);
+    }
+    else {
         p->options = xf86ReplaceIntOption(p->options, "fd", fd);
         p->options = xf86ReplaceIntOption(p->options, "libseat_id", id);
-        LogMessage(X_INFO, "seatd_libseat opened %s (%d:%d)\n", path, id,  fd);
+        LogMessage(X_INFO, "seatd_libseat opened %s (%d:%d)\n", path, id, fd);
     }
 }


@@ -275,19 +283,20 @@ seatd_libseat_close_device(InputInfoPtr p)
     char *path = xf86CheckStrOption(p->options, "Device", NULL);
     int fd = xf86CheckIntOption(p->options, "fd", -1);
     int id = xf86CheckIntOption(p->options, "libseat_id", -1);
+
     LogMessage(X_INFO, "seatd_libseat try close %s (%d:%d)\n", path, id, fd);
     if (!libseat_active())
         return;
     if (fd < 0) {
         LogMessage(X_ERROR, "seatd_libseat device not open (%s)\n", path);
-    return;
+        return;
     }
     if (id < 0) {
         LogMessage(X_ERROR, "seatd_libseat no libseat ID\n");
-    return;
+        return;
     }
     if (libseat_close_device(seat_info.client, id)) {
-    LogMessage(X_ERROR, "seatd_libseat close failed %d\n", -errno);
+        LogMessage(X_ERROR, "seatd_libseat close failed %d\n", -errno);
     }
     close(fd);
 }
-- 
2.39.0


>From b211306e06f3946d97d13c745fe70fc7302f834e Mon Sep 17 00:00:00 2001
From: Adam Sampson <ats@???>
Date: Mon, 19 Dec 2022 14:11:13 +0000
Subject: [PATCH 2/2] Remove unnecessary conditionals.

---
hw/xfree86/common/xf86Init.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 6c3668229..0119d912f 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -340,9 +340,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
             DoShowOptions();


         dbus_core_init();
-#ifdef SEATD_LIBSEAT
         seatd_libseat_init();
-#endif
         systemd_logind_init();


         /* Do a general bus probe.  This will be a PCI probe for x86 platforms */
@@ -851,9 +849,7 @@ ddxGiveUp(enum ExitCode error)
     if (xorgHWOpenConsole)
         xf86CloseConsole();


-#ifdef SEATD_LIBSEAT
     seatd_libseat_fini();
-#endif
     systemd_logind_fini();
     dbus_core_fini();


--
2.39.0