dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
984f77
From 54a8d932442d02f5a7dbf6038c8f557ce41f468b Mon Sep 17 00:00:00 2001
984f77
From: David Tardon <dtardon@redhat.com>
984f77
Date: Fri, 10 Jun 2022 15:07:01 +0200
984f77
Subject: [PATCH] logind-session-dbus: allow to set display name via dbus
984f77
984f77
Currently, the only way to set display name of a graphical session is to
984f77
pass it to CreateSession(). But modern display managers like gdm start
984f77
the display server as part of the user session, which means that the
984f77
display name isn't known yet when the session is being created. Hence,
984f77
let's make it possible to set it later.
984f77
984f77
(cherry picked from commit 4885d7490b23e08d8444e5a68927ce9ce8727e5a)
984f77
984f77
Resolves: #1857969
984f77
---
984f77
 src/login/logind-session-dbus.c       | 26 ++++++++++++++++++++++++++
984f77
 src/login/logind-session.c            | 20 ++++++++++++++++++++
984f77
 src/login/logind-session.h            |  1 +
984f77
 src/login/org.freedesktop.login1.conf |  4 ++++
984f77
 4 files changed, 51 insertions(+)
984f77
984f77
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
984f77
index 03585b7f8e..c935959e02 100644
984f77
--- a/src/login/logind-session-dbus.c
984f77
+++ b/src/login/logind-session-dbus.c
984f77
@@ -381,6 +381,31 @@ static int method_release_control(sd_bus_message *message, void *userdata, sd_bu
984f77
         return sd_bus_reply_method_return(message, NULL);
984f77
 }
984f77
 
984f77
+static int method_set_display(sd_bus_message *message, void *userdata, sd_bus_error *error) {
984f77
+        Session *s = userdata;
984f77
+        const char *display;
984f77
+        int r;
984f77
+
984f77
+        assert(message);
984f77
+        assert(s);
984f77
+
984f77
+        r = sd_bus_message_read(message, "s", &display);
984f77
+        if (r < 0)
984f77
+                return r;
984f77
+
984f77
+        if (!session_is_controller(s, sd_bus_message_get_sender(message)))
984f77
+                return sd_bus_error_set(error, BUS_ERROR_NOT_IN_CONTROL, "You must be in control of this session to set display");
984f77
+
984f77
+        if (!SESSION_TYPE_IS_GRAPHICAL(s->type))
984f77
+                return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Setting display is only supported for graphical sessions");
984f77
+
984f77
+        r = session_set_display(s, display);
984f77
+        if (r < 0)
984f77
+                return r;
984f77
+
984f77
+        return sd_bus_reply_method_return(message, NULL);
984f77
+}
984f77
+
984f77
 static int method_take_device(sd_bus_message *message, void *userdata, sd_bus_error *error) {
984f77
         Session *s = userdata;
984f77
         uint32_t major, minor;
984f77
@@ -523,6 +548,7 @@ const sd_bus_vtable session_vtable[] = {
984f77
         SD_BUS_METHOD("TakeDevice", "uu", "hb", method_take_device, SD_BUS_VTABLE_UNPRIVILEGED),
984f77
         SD_BUS_METHOD("ReleaseDevice", "uu", NULL, method_release_device, SD_BUS_VTABLE_UNPRIVILEGED),
984f77
         SD_BUS_METHOD("PauseDeviceComplete", "uu", NULL, method_pause_device_complete, SD_BUS_VTABLE_UNPRIVILEGED),
984f77
+        SD_BUS_METHOD("SetDisplay", "s", NULL, method_set_display, SD_BUS_VTABLE_UNPRIVILEGED),
984f77
 
984f77
         SD_BUS_SIGNAL("PauseDevice", "uus", 0),
984f77
         SD_BUS_SIGNAL("ResumeDevice", "uuh", 0),
984f77
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
984f77
index e4c8bb36f6..1143a834a4 100644
984f77
--- a/src/login/logind-session.c
984f77
+++ b/src/login/logind-session.c
984f77
@@ -953,6 +953,26 @@ void session_set_locked_hint(Session *s, bool b) {
984f77
         session_send_changed(s, "LockedHint", NULL);
984f77
 }
984f77
 
984f77
+int session_set_display(Session *s, const char *display) {
984f77
+        int r;
984f77
+
984f77
+        assert(s);
984f77
+        assert(display);
984f77
+
984f77
+        if (streq(s->display, display))
984f77
+                return 0;
984f77
+
984f77
+        r = free_and_strdup(&s->display, display);
984f77
+        if (r < 0)
984f77
+                return r;
984f77
+
984f77
+        session_save(s);
984f77
+
984f77
+        session_send_changed(s, "Display", NULL);
984f77
+
984f77
+        return 1;
984f77
+}
984f77
+
984f77
 static int session_dispatch_fifo(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
984f77
         Session *s = userdata;
984f77
 
984f77
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
984f77
index 7d17d9a25f..9bd0c96a03 100644
984f77
--- a/src/login/logind-session.h
984f77
+++ b/src/login/logind-session.h
984f77
@@ -123,6 +123,7 @@ int session_get_idle_hint(Session *s, dual_timestamp *t);
984f77
 void session_set_idle_hint(Session *s, bool b);
984f77
 int session_get_locked_hint(Session *s);
984f77
 void session_set_locked_hint(Session *s, bool b);
984f77
+int session_set_display(Session *s, const char *display);
984f77
 int session_create_fifo(Session *s);
984f77
 int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error);
984f77
 int session_stop(Session *s, bool force);
984f77
diff --git a/src/login/org.freedesktop.login1.conf b/src/login/org.freedesktop.login1.conf
984f77
index dcde0c22c6..b780ae08cf 100644
984f77
--- a/src/login/org.freedesktop.login1.conf
984f77
+++ b/src/login/org.freedesktop.login1.conf
984f77
@@ -314,6 +314,10 @@
984f77
                        send_interface="org.freedesktop.login1.User"
984f77
                        send_member="Kill"/>
984f77
 
984f77
+                
984f77
+                       send_interface="org.freedesktop.login1.Session"
984f77
+                       send_member="SetDisplay"/>
984f77
+
984f77
                 <allow receive_sender="org.freedesktop.login1"/>
984f77
         </policy>
984f77