Systemd/src/login
David Herrmann 49e6fdbf14 logind: introduce session "positions"
logind has no concept of session ordering. Sessions have a unique name,
some attributes about the capabilities and that's already it. There is
currently no stable+total order on sessions. If we use the logind API to
switch between sessions, we are faced with an unordered list of sessions
we have no clue of.

This used to be no problem on seats with VTs or on seats with only a
single active session. However, with the introduction of multi-session
capability for seats without VTs, we need to find a way to order sessions
in a stable way.

This patch introduces session "positions". A position is a simple integer
assigned to a session which is never changed implicitly (currently, we
also don't change it explicitly, but that may be changed someday). For
seats with VTs, we force the position to be the same as the VTnr. Without
VTs, we simply find the lowest unassigned number and use it as position.
If position-assignment fails or if, for any reason, we decide to not
assign a position to a session, the position is set to 0 (which is treated
as invalid position).
During session_load() or if two sessions have the same VTnr, we may end up
with two sessions with the same position (this shouldn't happen, but lets
be fail-safe in case some other part of the stack fails). This case is
dealt with gracefully by ignoring any session but the first session
assigned to the position. Thus, session->pos is a hint, seat->positions[i]
is the definite position-assignment. Always verify both match in case you
need to modify them!

Additionally, we introduce SwitchTo(unsigned int) on the seat-dbus-API.
You can call it with any integer value != 0 and logind will try to switch
to the request position. If you implement a compositor or any other
session-controller, you simply watch for ctrl+alt+F1 to F12 and call
SwitchTo(Fx). logind will figure a way out deal with this number.
For convenience, we also introduce SwitchToNext/Previous(). It should be
called on ctrl+alt+Left/Right (like the kernel-console used to support).

Note that the public API (SwitchTo*()) is *not* bound to the underlying
logic that is implemented now. We don't export "session-positions" on the
dbus/C API! They are an implementation detail. Instead, the SwitchTo*()
API is supposed to be a hint to let logind choose the session-switching
logic. Any foreground session-controller is free to enumerate/order
existing sessions according to their needs and call Session.Activate()
manually. But the SwitchTo*() API provides a uniform behavior across
session-controllers.

Background: Session-switching keys depend on the active keymap. The XKB
specification provides the XKB_KEY_XF86Switch_VT_1-12 key-symbols which
have to be mapped by all keymaps to allow session-switching. It is usually
bound to ctrl+alt+Fx but may be set differently. A compositor passes any
keyboard input to XKB before passing it to clients. In case a key-press
invokes the XKB_KEY_XF86Switch_VT_x action, the keypress is *not*
forwarded to clients, but instead a session-switch is scheduled.

This actually prevents us from handling these keys outside of the session.
If an active compositor has a keymap with a different mapping of these
keys, and logind itself tries to catch these combinations, we end up with
the key-press sent to the compositor's clients *and* handled by logind.
This is *bad* and we must avoid this. The only situation where a
background process is allowed to handle key-presses is debugging and
emergency-keys. In these cases, we don't care for keymap mismatches and
accept the double-event. Another exception is unmapped keys like
PowerOff/Suspend (even though this one is controversial).
2014-01-20 22:30:01 +01:00
..
.gitignore login: properly detect MIMO USB displays 2012-05-31 01:20:37 +02:00
70-power-switch.rules login: Use the GOTO properly in udev rule 2012-05-30 18:34:28 +02:00
70-uaccess.rules uaccess: Add new DRM render nodes 2013-11-12 18:11:43 +01:00
71-seat.rules.in Move udevadm to rootbindir 2013-03-11 07:18:33 +01:00
73-seat-late.rules.in relicense to LGPLv2.1 (with exceptions) 2012-04-12 00:24:39 +02:00
inhibit.c bus: introduce concept of a default bus for each thread and make use of it everywhere 2013-11-12 00:12:43 +01:00
libsystemd-login.pc.in relicense to LGPLv2.1 (with exceptions) 2012-04-12 00:24:39 +02:00
libsystemd-login.sym libsystemd-login: add sd_session_get_remote_{host, user} 2013-12-21 22:02:57 -05:00
login-shared.c login: fix login_is_valid test 2013-09-16 11:10:55 -05:00
login-shared.h login: fix login_is_valid test 2013-09-16 11:10:55 -05:00
loginctl.c loginctl: fix output of type with class 2013-12-22 19:12:57 -05:00
logind-acl.c core,logind,networkd: check for udev device initialization via enumeration matches 2013-12-18 18:21:28 +01:00
logind-acl.h use #pragma once instead of foo*foo #define guards 2012-07-19 12:30:59 +02:00
logind-action.c logind: log which process is delaying suspend and not closing locks 2013-11-27 02:39:19 +01:00
logind-action.h conf-parser: distinguish between multiple sections with the same name 2013-11-25 19:35:44 +01:00
logind-button.c event: be more conservative when returning errors from event handler callbacks 2013-12-13 04:06:43 +01:00
logind-button.h use #pragma once instead of foo*foo define guards 2013-11-18 20:28:54 -05:00
logind-core.c logind: make VT numbers unsigned 2013-11-28 17:38:16 +01:00
logind-dbus.c logind: wait for the user service to finish startup before completing login attempt 2014-01-09 06:51:09 +08:00
logind-device.c Remove dead code and unexport some calls 2013-11-08 18:12:45 +01:00
logind-device.h Remove dead code and unexport some calls 2013-11-08 18:12:45 +01:00
logind-gperf.gperf logind: port over to use scopes+slices for all cgroup stuff 2013-07-02 01:48:55 +02:00
logind-inhibit.c __thread --> thread_local for C11 compat 2013-12-17 21:45:43 +01:00
logind-inhibit.h logind: log which process is delaying suspend and not closing locks 2013-11-27 02:39:19 +01:00
logind-seat-dbus.c logind: introduce session "positions" 2014-01-20 22:30:01 +01:00
logind-seat.c logind: introduce session "positions" 2014-01-20 22:30:01 +01:00
logind-seat.h logind: introduce session "positions" 2014-01-20 22:30:01 +01:00
logind-session-dbus.c logind: wait for the user service to finish startup before completing login attempt 2014-01-09 06:51:09 +08:00
logind-session-device.c logind: ignore failing close() on session-devices 2013-11-28 15:16:49 +01:00
logind-session-device.h logind: remove fbdev session-device support 2013-10-01 18:08:54 +02:00
logind-session.c logind: introduce session "positions" 2014-01-20 22:30:01 +01:00
logind-session.h logind: introduce session "positions" 2014-01-20 22:30:01 +01:00
logind-user-dbus.c bus: decorate the various object vtables with SD_BUS_VTABLE_PROPERTY_CONST where appropriate 2013-12-22 03:50:52 +01:00
logind-user.c logind: remove dead variable 2013-12-21 22:54:03 -05:00
logind-user.h logind: remove dead variable 2013-12-21 22:54:03 -05:00
logind.c core,logind,networkd: check for udev device initialization via enumeration matches 2013-12-18 18:21:28 +01:00
logind.conf logind: port over to use scopes+slices for all cgroup stuff 2013-07-02 01:48:55 +02:00
logind.h logind: make VT numbers unsigned 2013-11-28 17:38:16 +01:00
Makefile logind: move logind into its own subdirectory 2011-12-31 03:16:08 +01:00
multi-seat-x.c multi-seat-x: drop a lot of unnecessary code 2012-09-21 17:03:40 +02:00
org.freedesktop.login1.conf bus: introduce "trusted" bus concept and encode access control in object vtables 2013-12-10 16:52:49 +00:00
org.freedesktop.login1.policy.in logind: if a user is sitting in front of the computer and can shutdown the machine anyway he should also be able to reboot it 2013-09-26 20:31:37 +02:00
org.freedesktop.login1.service relicense to LGPLv2.1 (with exceptions) 2012-04-12 00:24:39 +02:00
pam-module.c pam: skip DBUS_SESSION_BUS_ADDRESS export when kdbus is not active 2014-01-12 01:45:42 +08:00
sd-login.c libsystemd-login: add sd_session_get_remote_{host, user} 2013-12-21 22:02:57 -05:00
sysfs-show.c loginctl: when showing device tree of seats with no devices show something useful 2013-12-18 18:21:28 +01:00
systemd-user Add pam configuration to allow user sessions to work out of the box 2013-09-11 15:35:06 -04:00
test-inhibit.c login: port test-inhibit to libsystemd-bus 2013-11-05 21:34:42 +01:00
test-login-shared.c Add more tests and fix capability logging 2013-09-19 16:22:59 -05:00
test-login-tables.c tests: add tests for string lookup tables 2013-07-05 01:36:16 -04:00
test-login.c libsystemd-login: add sd_session_get_remote_{host, user} 2013-12-21 22:02:57 -05:00
user-sessions.c user-sessions: modernizations 2013-11-05 01:13:05 +01:00