Commit Graph

1081 Commits

Author SHA1 Message Date
Lennart Poettering b921711248 logind: validate /run/user/1000 before we set it
Let's be safe than sorry, in particular as logind doesn't set it up
anymore, but user-runtime-dir@.service does, and logind doesn't really
track success of that.
2018-10-13 13:01:08 +02:00
Lennart Poettering 4e5b605af2 logind: automatically GC lingering users for who now user@.service (nor slice, not runtime dir service) is running anymore
This heavily borrows from @intelfx' PR #5546, but watches all three
units that are associated with a user now: the slice, the user@.service
and user-runtime-dir@.service.

The logic and reasoning behind it is the same though: there's no value
in keeping lingering users around if all their three services are gone.

Replaces: #5546
Fixes: #4162
2018-10-13 12:59:29 +02:00
Lennart Poettering 6996df9b86 logind: improve error propagation of user_check_linger_file()
Let's make this a bit prettier, and propagate unexpected access() errors
correctly.

(The callers of this function will suppress them, but it's nicer of they
do that, rather than us doing that twice in both the callers and the
callees)
2018-10-13 12:59:29 +02:00
Lennart Poettering d5ac9d0602 logind: add a RequiresMountsFor= dependency from the session scope unit to the home directory of the user
This is useful so that during shutdown scope units are always terminated
before the mounts necessary for the home directory.

(Ideally we'd also add a similar dependency from the user@.service
instance to the home directory, but this isn't as easy as that service
is defined statically and not dynamically, and hence not easy to modify
dynamically, in particular when it comes to deps)
2018-10-13 12:59:29 +02:00
Lennart Poettering 07ee5adb35 logind: change user-runtime-dir to query runtime dir size from logind via the bus
I think this is a slightly cleaner approach than parsing the
configuration file at multiple places, as this way there's only a single
reload cycle for logind.conf, and that's systemd-logind.service's
runtime.

This means that logind and dbus become a requirement of
user-runtime-dir, but given that XDG_RUNTIME_DIR is not set anyway
without logind and dbus around this isn't really any limitation.

This also simplifies linking a bit as this means user-runtime-dir
doesn't have to link against any code of logind itself.
2018-10-13 12:59:29 +02:00
Lennart Poettering 3d0ef5c7e0 logind: optionally watch utmp for login data
This allows us to determine the TTY an ssh session is for, which is
useful to to proper idle detection for ssh sessions.

Fixes: #9622
2018-10-13 12:59:29 +02:00
Lennart Poettering 238794b150 logind: add hashtable for finding session by leader PID
This is useful later on, when we quickly want to find the session for a
leader PID.
2018-10-13 12:59:29 +02:00
Lennart Poettering 9afe9efb93 logind: optionally, keep the user@.service instance for eached logged in user around for a while
This should speed up rapid logout/login cycles a bit.

By default this timeout is now set to 10s.

Fixes: #8410
Replaces: #4434
2018-10-13 12:59:29 +02:00
Lennart Poettering 061c6607a9 logind: minor session time handling tweaks 2018-10-13 12:59:29 +02:00
Lennart Poettering 25a1ab4ed4 logind: rework how we manage the slice and user-runtime-dir@.service unit for each user
Instead of managing it explicitly, let's simplify things and rely on
regular Wants=/Requires= dependencies to pull in these units from
user@.service and the session scope, and StopWhenUneeded= to stop these
auxiliary units again. This way, they can be pulled in easily by
unrelated units too.

This simplifies things quite a bit: for each session we now only need to
manage the session scope, and for each user the user@.service, the other
units are not something we need to manage anymore.

This patch also makes sure that if user@.service of a user is masked we
will continue to work, and user-runtime-dir@.service will still be
correctly pulled in, as it is now a dependency of the scope unit.

Fixes: #9461
Replaces: #5546
2018-10-13 12:59:29 +02:00
Lennart Poettering ea3a7cf6c3 logind: don't clobber bus error structure if we don't fail 2018-10-13 12:59:29 +02:00
Lennart Poettering e6958b7ea3 logind: propagate session stop errors
Let's propagate errors from stopping sessions via seat_stop(). This is
similar to how we propagate such errors in user_stop() for all sessions
associated with a user.

Note that we propagate these errors, but we don't abort the function.
2018-10-13 12:59:29 +02:00
Lennart Poettering b1951bc83f logind: introduce little helper that checks whether a session is ready 2018-10-13 12:59:29 +02:00
Lennart Poettering 1b88ed3b7d logind: use TAKE_PTR() where we can 2018-10-13 12:59:29 +02:00
Lennart Poettering d5ddc93015 logind: prefer strjoin() over asprintf() 2018-10-13 12:59:29 +02:00
Lennart Poettering 709d058756 logind: don't rely on downgrade-to-bool 2018-10-13 12:59:29 +02:00
Lennart Poettering 75bbdf478c logind: voidify a few calls 2018-10-13 12:59:29 +02:00
Lennart Poettering e555d12635 logind: make better use of logging functions 2018-10-13 12:59:29 +02:00
Lennart Poettering 04857cd801 logind: never elect a session that is stopping as display 2018-10-13 12:59:29 +02:00
Lennart Poettering bd26aee1f6 logind: make unit/job active checking more debuggable
Let's log the error messages if we get any at debug level.
2018-10-13 12:59:29 +02:00
Lennart Poettering cce08496e7 logind: fix bad error propagation 2018-10-13 12:59:29 +02:00
Lennart Poettering d88ffeeeef logind: correct bad clean-up path 2018-10-13 12:59:29 +02:00
Lennart Poettering d865bc024b logind: save/restore User object's "stopping" field during restarts
Whether we are stopping or not is highly relevant, hence don't forget it
across restarts.
2018-10-13 12:59:29 +02:00
Lennart Poettering 0b6d55cae9 logind: improve logging in manager_connect_console()
let's make sure we log about every failure

Also, complain about systems where /dev/tty0 exists but
/sys/class/tty/tty0/active does not. Such systems (usually container
environments) are pretty broken as they mount something that is not a VC
to /dev/tty0 and they really shouldn't.

Systems should either have a VC or not, but not badly fake one by
mounting things wildly.

This just adds a warning message, as before we'll simply turn off VC
handling in this case.
2018-10-13 12:59:29 +02:00
Lennart Poettering b25ba6cf67 logind: initialize Manager object with structure initialization too 2018-10-13 12:59:29 +02:00
Lennart Poettering 4417640013 logind: turn of stdio locking when writing session files too
This just copies what we already do for user and seat files to session
files.
2018-10-13 12:59:29 +02:00
Lennart Poettering 1c8280fd47 logind: fix serialization/deserialization of user's "display session"
Previously this was serialized as part of the user object. This didn't
work however, as we load users first, and sessions seconds and hence
referencing a session from the user load logic cannot work.

Fix this by storing an IS_DISPLAY property along with each session, and
make the session with this set display session when it is loaded.
2018-10-13 12:59:29 +02:00
Lennart Poettering 8c29a45709 logind: rework Seat/Session/User object allocation and freeing a bit
Let's update things a bit to follow current practices:

- User structure initialization rather than zero-initialized allocation

- Always propagate proper errors from allocation functions

- Use _cleanup_ for freeing objects when allocation fails half-way

- Make destructors return NULL
2018-10-13 12:59:29 +02:00
Lennart Poettering a6ee956610
Merge pull request #10356 from dtardon/covscan
assorted coverity/clang fixes
2018-10-12 18:43:04 +02:00
David Tardon e99742ef3e login: avoid leak of name returned by uid_to_name() 2018-10-12 14:51:35 +02:00
David Tardon f369f47c26 be consistent about sun_path length
Most places use the whole buffer for name, without leaving extra space
for the trailing NUL.
2018-10-12 12:38:49 +02:00
Lennart Poettering 8e04444385 journalctl: port JSON output mode to new JSON API
Also, while we are at it, beef it up, by adding json-seq support (i.e.
https://tools.ietf.org/html/rfc7464). This is particularly useful in
conjunction with jq's --seq switch.
2018-10-11 17:25:27 +02:00
Lennart Poettering 1634ebb54a
Merge pull request #10262 from keszybz/hibres-disable
Switches to disable hibernation and/or resuming
2018-10-08 21:39:54 +02:00
Zbigniew Jędrzejewski-Szmek 5fdf2d51c2 shared/sleep-config: forbid hibernation if resume= is not configured 2018-10-08 18:20:58 +02:00
Ray Strode ad1bf59c67 logind: ensure seat0 CanGraphical state is written
For non-`seat0` seats, attaching a graphics card to a seat can
lead to it getting created. This is because the graphics device
is a "master device" which means that device is a seat-defining
device.

`seat0` may get created, even before the graphics driver is loaded,
though. This is because the graphics driver is loaded
asynchronously at startup, and `seat0` is the primary seat of
system, associated with the system VTs.

When a graphics card is attached to a seat the `CanGraphical`
property on that seat will flip to `true`.

For seats that haven't been created yet (non-`seat0` seats), this
leads to `seat_start` getting called which ultimately causes the
seat to get serialized to `/run/systemd/seats`.

For `seat0`, which is already created, `seat_start` will return
immediately, which means the updated `CanGraphical` state will
never get written to `/run/systemd/seats`.

The end result is that clients querying `sd_seat_can_graphical`
won't get the correct answer for `seat0` in cases where the
graphics device takes a long time to load until some other peice
of seat state is updated.

This commit fixes the problem by calling `seat_save` explicitly
for already running seats at the time a graphics device is
attached.
2018-10-06 16:52:48 +02:00
Lennart Poettering 4295fd9e82
Merge pull request #10163 from poettering/inhibit-format-table
systemd-inhibit --list: port to format-table.c
2018-09-25 10:24:30 +02:00
Lennart Poettering 6ac386855c logind: fix blacklist/whitelist confusion in comment (#10165)
Triggered by this:

602a41c22a (r30575293)
2018-09-25 07:02:41 +09:00
Lennart Poettering a942661787 inhibit: use format-table to format systemd-inhibit --list
This changes the output a bit, as the previous multi-line output of each
inhibitor is changed to a single line, but it does unify the output look
with the one of our other tools. Moreover this adds proper sorting.
2018-09-24 19:21:00 +02:00
Lennart Poettering 2f47ef04ea inhibit: normalize variable types
When we parse an "u" from an sd_bus_message then we need to do that into
a uint32_t, not a pid_t or uid_t, even if this is likely the same.

Also, let's count objects we keep in memory as size_t as usual.
2018-09-24 19:21:00 +02:00
Lennart Poettering 0e6872cdfc inhibit: normalize when we log about failures to list inhibitors
let's print log messages about all types of errors inside of the
function, since otherwise we might sometimes log twice about some
specific cases.
2018-09-24 19:21:00 +02:00
Yu Watanabe c679e12af1 tree-wide: drop unnecessary initializations 2018-09-23 17:18:50 +09:00
Yu Watanabe 8a80712bcd logind-acl: replace strdup()+set_consume() by set_put_strdup() 2018-09-23 17:18:50 +09:00
Yu Watanabe 403660c508 tree-wide: use streq() instead of streq_ptr() 2018-09-23 17:18:50 +09:00
Zbigniew Jędrzejewski-Szmek 9035119518
Merge pull request #9958 from yuwata/sd-device-enum-set
sd-device: make sd_device_enumerator_get_*_next() not destroy the list
2018-09-15 18:33:18 +02:00
Yu Watanabe eda193578e bus-util: make --property= optionally take value 2018-09-12 12:11:25 +09:00
Jürg Billeter da0da5eccf pam_systemd: support use in PID namespaces
Pass 0 as leader PID to CreateSession to let logind use the PID from the
D-Bus credentials. This allows use of pam_systemd in PID namespaces.
2018-09-10 19:04:21 +02:00
Yu Watanabe 8437c0593f tree-wide: replace device_enumerator_scan_devices()+FOREACH_DEVICE_AND_SUBSYSTEM() by FOREACH_DEVICE() 2018-09-10 16:48:37 +09:00
Yu Watanabe e132a04392 login/sysfs-show: use device_enumerator_get_devices() 2018-09-10 16:47:35 +09:00
Alan Jenkins 81375d8026 user-runtime-dir: fix selinux regression
Fix #9993.  When this code was split out to user-runtime-dir, it forgot to
include the call to mac_selinux_init().  So mkdir_label() stopped working.

Fixes: a9f0f5e501 ("logind: split %t directory creation to a helper
unit")
2018-09-03 14:09:21 +02:00
Franck Bui 49679ff70f logind: make use of vtnr_from_tty() in seat_read_active_vt() (#9923)
No functional changes.
2018-08-24 16:20:51 +09:00