|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From b12e56156e5f363ebb8dc4ea5c10f5fd0665dc9d Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: David Herrmann <dh.herrmann@gmail.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Mon, 1 Sep 2014 14:04:44 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] login: simplify controller handling
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Simplify the way we handler session-controllers and fix several
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
shortcomings:
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* send ReleaseDevice() signals on forced session takeover
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* fix mem-leaks for busnames in case VT preparation fails (non-critical)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* avoid passing pre-allocated names to helpers
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/login/logind-session.c | 55 +++++++++++++++++++++++-----------------------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
1 file changed, 28 insertions(+), 27 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 58453b516f..10a43a4a30 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/login/logind-session.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/login/logind-session.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1059,32 +1059,30 @@ bool session_is_controller(Session *s, const char *sender) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return streq_ptr(s->controller, sender);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-static void session_swap_controller(Session *s, char *name) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+static void session_release_controller(Session *s, bool notify) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ _cleanup_free_ char *name = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
SessionDevice *sd;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- char *c;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (s->controller) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- c = s->controller;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- s->controller = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- manager_drop_busname(s->manager, c);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- free(c);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (!s->controller)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- /* Drop all devices as they're now unused. Do that after the
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * controller is released to avoid sending out useles
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * dbus signals. */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- while ((sd = hashmap_first(s->devices)))
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- session_device_free(sd);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ name = s->controller;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (!name)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- session_restore_vt(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* By resetting the controller before releasing the devices, we won't
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * send notification signals. This avoids sending useless notifications
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * if the controller is released on disconnects. */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (!notify)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ s->controller = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- s->controller = name;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- session_save(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ while ((sd = hashmap_first(s->devices)))
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_device_free(sd);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ s->controller = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ manager_drop_busname(s->manager, name);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int session_set_controller(Session *s, const char *sender, bool force) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- char *t;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ _cleanup_free_ char *name = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1095,15 +1093,13 @@ int session_set_controller(Session *s, const char *sender, bool force) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (s->controller && !force)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return -EBUSY;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- t = strdup(sender);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (!t)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ name = strdup(sender);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (!name)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return -ENOMEM;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = manager_watch_busname(s->manager, sender);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (r) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- free(t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = manager_watch_busname(s->manager, name);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/* When setting a session controller, we forcibly mute the VT and set
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* it into graphics-mode. Applications can override that by changing
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1115,11 +1111,14 @@ int session_set_controller(Session *s, const char *sender, bool force) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* or reset the VT in case it crashed/exited, too. */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = session_prepare_vt(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- free(t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ manager_drop_busname(s->manager, name);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- session_swap_controller(s, t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_release_controller(s, true);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ s->controller = name;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ name = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_save(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1130,7 +1129,9 @@ void session_drop_controller(Session *s) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (!s->controller)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- session_swap_controller(s, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_release_controller(s, false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_save(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ session_restore_vt(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static const char* const session_state_table[_SESSION_STATE_MAX] = {
|