ryantimwilson / rpms / systemd

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