Commit Graph

55 Commits

Author SHA1 Message Date
Lennart Poettering c5a11ae268 logind: enforce a limit on inhibitors we hand out
For similar reasons as the recent addition of a limit on sessions.

Note that we don't enforce a limit on inhibitors per-user currently, but
there's an implicit one, since each inhibitor takes up one fd, and fds are
limited via RLIMIT_NOFILE, and the limit on the number of processes per user.
2016-05-05 22:50:09 +02:00
Lennart Poettering 183e073842 logind: enforce a limit on current user sessions
We really should put limits on all resources we manage, hence add one to the
number of concurrent sessions, too. This was previously unbounded, hence set a
relatively high limit of 8K by default.

Note that most PAM setups will actually invoke pam_systemd prefixed with "-",
so that the return code of pam_systemd is ignored, and the login attempt
succeeds anyway. On systems like this the session will be created but is not
tracked by systemd.
2016-05-05 22:50:09 +02:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering 90558f3158 logind: add a new UserTasksMax= setting to logind.conf
This new setting configures the TasksMax= field for the slice objects we
create for each user.

This alters logind to create the slice unit as transient unit explicitly
instead of relying on implicit generation of slice units by simply
starting them. This also enables us to set a friendly description for
slice units that way.
2015-11-13 19:50:52 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Daniel Mack 1389f4b958 logind: allow dry run variants for scheduled shutdowns
Allow passing a "dry-" prefix to the action parameter passed to
.ScheduleShutdown(). When strings with this prefix are passed,
the scheduled action will not take place. Instead, an info message
is logged.
2015-09-09 17:52:11 +02:00
Daniel Mack 3cde9e8fa0 logind: switch to sd_bus_track helper
Let logind use the sd_bus_track helper object to track the controllers of
sessions. This does not only remove quite some code but also kills the
unconditional matches for all NameOwnerChanged signals.

The latter is something we should never ever do, as it wakes up the daemon
every time a client connects, which doesn't scale.
2015-08-05 17:06:45 +02:00
Daniel Mack 418b22b88f logind: fix delayed execution regression
Commit c0f32805 ("logind: use sd_event timer source for inhibitor
logic") reworked the main loop logic of logind so that it uses a
real timeout callback handler to execute delayed functions.

What the old code did, however, was to call those functions on
every iteration in the main loop, not only when the timeout
expired.

Restore that behavior by bringing back manager_dispatch_delayed(),
and call it from manager_run(). The internal event source callback
manager_inhibit_timeout_handler() was turned into a wrapper of
manager_dispatch_delayed() now.
2015-06-25 17:18:41 +02:00
Lennart Poettering 602a41c22a logind: rework display counting when detecting whether the system is docked
Previously, we'd just count connected displays, and if there was 2 or
more we assumed a "docked" state.

With this change we now:

- Only count external displays, ignore internal ones (which we detect by
  checking the connector name against a whitelist of known external plug
  types)

- We ignore connectors which are explicitly disabled

- We then compare the count with >= 1 rather than >= 2 as before

This new logic has the benefit that systems that disconnect the internal
display when the lid is closed are better supported. Also, explicitly
disabled ports do not confuse the algorithm anymore.

This new algorithm has been suggested here:

http://lists.freedesktop.org/archives/intel-gfx/2015-June/068821.html

This also makes two functions static, that are not used outside of their
.c files.
2015-06-17 15:41:25 +02:00
Lennart Poettering 190700621f sd-bus: drop bus parameter from message callback prototype
This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().
2015-04-29 18:36:25 +02:00
Daniel Mack 867c37f6bb logind: add support for /run/nologin and /run/systemd/shutdown/scheduled
Port over more code from shutdownd and teach logind to write /run/nologin at
least 5 minutes before the system is going down, and
/run/systemd/shutdown/scheduled when a shutdown is scheduled.
2015-04-24 17:48:12 +02:00
Daniel Mack e2fa5721c3 logind: add code for UTMP wall messages
Add a timer to print UTMP wall messages so that it repeatedly informs users
about a scheduled shutdown:

 * every 1 minute with less than 10 minutes to go
 * every 15 minutes with less than 60 minutes to go
 * every 30 minutes with less than 180 minutes (3 hours) to go
 * every 60 minutes if more than that to go

This functionality only active if the .EnableWallMessages DBus property
is set to true. Also, a custom string can be added to the wall message,
set through the WallMessagePrefix property.
2015-04-24 17:48:12 +02:00
Daniel Mack 8aaa023ae7 logind: add .ScheduleShutdown and .CancelScheduledShutdown methods
Add a method called ScheduleShutdown in org.freedesktop.login1.Manager
which adds a timer to shut down the system at a later point in time.

The first argument holds the type of the schedule that is about to
happen, and must be one of 'reboot', 'halt' or 'poweroff'.

The second argument specifies the absolute time, based on
CLOCK_REALTIME in nanoseconds, at which the the operation should be
executed.

To cancel a previously scheduled shutdown, the CancelScheduledShutdown()
can be called, which returns a bool, indicating whether a scheduled
timeout was cancelled.

Also add a new property called ScheduledShutdown which returns the
equivalent to what was passed in via ScheduleShutdown, as '(st)' type.
2015-04-24 17:48:12 +02:00
Daniel Mack 905f0a39ae logind: make local functions static
make manager_gc(), manager_startup(), manager_new(), manager_free()
and manager_run() static, and kill their forward declarations.
2015-04-24 17:48:12 +02:00
Daniel Mack c0f3280508 logind: use sd_event timer source for inhibitor logic
Instead of open-coding the delayed action and inhibit timeout logic,
switch over to a real sd_event_source based implementation.

This is not only easier to read but also allows us to add more timers
in the future.
2015-04-24 17:48:12 +02:00
David Herrmann 9d10cbee89 login: make hold-off timeout configurable
This introduces 'HoldoffTimeoutSec' to logind.conf to make
IGNORE_LID_SWITCH_{SUSPEND,STARTUP}_USEC configurable.

Background: If an external monitor is connected, or if the system is
docked, we want to ignore LID events. This is required to support setups
where a laptop is used with external peripherals while the LID is closed.
However, this requires us to probe all hot-plugged devices before reacting
to LID events. But with modern buses like USB, the standards do not impose
any timeout on the slots, so we have no chance to know whether a given
slot is used or not. Hence, after resume and startup, we have to wait a
fixed timeout to give the kernel a chance to probe devices. Our timeout
has always been generous enough to support even the slowest devices.
However, a lot of people didn't use these features and wanted to disable
the hold-off timer. Now we provide a knob to do that.
2015-03-06 14:37:09 +01:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering 309a29dfd2 logind: when a bus call is done on a session, user or seat, optionally determine them from the caller credentials
More specifically, if an operation is requested on a session with an
empty name, the caller's session is used. If an operation is requested
on a seat with an empty name, the seat of the caller's session is used.
Finally, if an operation on the user with UID -1 is requested, the user
of the client's session is used (and not the UID of the client!).
2015-01-09 18:35:36 +01:00
Ben Wolsieffer 3c56cab441 logind: add HandleLidSwitchDocked= option to logind.conf + documentation
https://bugs.freedesktop.org/show_bug.cgi?id=82485
2014-08-26 22:08:02 +02:00
Lennart Poettering 66cdd0f2d0 logind: automatically remove SysV + POSIX IPC objects when the users owning them fully log out 2014-03-14 01:49:44 +01:00
Lennart Poettering 1c231f5648 logind: make $XDG_RUNTIME_DIR a per-user tmpfs
This way each user allocates from his own pool, with its own size limit.

This puts the size limit by default to 10% of the physical RAM size but
makes it configurable in logind.conf.
2014-03-04 20:02:50 +01:00
Lennart Poettering f9cd6be10e logind: ignore lid switch events for 30s after each suspend and 3min after startup
This is needed to give USB docking stations and suchlike time to settle,
so that a display connected to an USB docking station can actually act
as a lid swith inhibitor correctly.

With this change we should have somewhat reliable docking station
support in place.
2014-03-03 20:57:09 +01:00
Lennart Poettering 6a79c58603 logind: ignore lid switch if more than 1 display is connected
Previously we expected the desktop environment to take an inhibitor
lock, but this opened a race on boot-up where logind might already be
running but no DE is active.

Hence, let's move checking for additional displays into logind. This
also opens up this logic for other DEs, given that only GNOME
implemented the inhibitor logic so far.
2014-03-03 19:32:43 +01:00
Lennart Poettering 2d62c530d2 logind: detect whether the system is docked, and if it is inhibit lid switch processing
This should make operation nicer with docking stations, but will not
cover anything that does not implement SW_DOCK.
2014-02-24 16:22:23 +01:00
Lennart Poettering ba4c5d93b7 logind: order all scopes after both systemd-logind.service and
systemd-user-sessions.service

This way at shutdown we can be sure that the sessions go away before the
network.
2014-02-07 17:49:16 +01:00
Lennart Poettering 5f41d1f10f logind: rework session shutdown logic
Simplify the shutdown logic a bit:

- Keep the session FIFO around in the PAM module, even after the session
  shutdown hook has been finished. This allows logind to track precisely
  when the PAM handler goes away.

- In the ReleaseSession() call start a timer, that will stop terminate
  the session when elapsed.

- Never fiddle with the KillMode of scopes to configure whether user
  processes should be killed or not. Instead, simply leave the scope
  units around when we terminate a session whose processes should not be
  killed.

- When killing is enabled, stop the session scope on FIFO EOF or after
  the ReleaseSession() timeout. When killing is disabled, simply tell
  PID 1 to abandon the scope.

Because the scopes stay around and hence all processes are always member
of a scope, the system shutdown logic should be more robust, as the
scopes can be shutdown as part of the usual shutdown logic.
2014-02-07 15:14:36 +01:00
David Herrmann 92bd5ff3a0 logind: make VT numbers unsigned
Fix the whole code to use "unsigned int" for vtnr. 0 is an invalid vtnr so
we don't need negative numbers at all.

Note that most code already assumes it's unsigned so in case there's a
negative vtnr, our code may, under special circumstances, silently break.
So this patch makes sure all sources of vtnrs verify the validity. Also
note that the dbus api already uses unsigned ints.
2013-11-28 17:38:16 +01:00
Lennart Poettering ebcf1f97de bus: rework message handlers to always take an error argument
Message handler callbacks can be simplified drastically if the
dispatcher automatically replies to method calls if errors are returned.

Thus: add an sd_bus_error argument to all message handlers. When we
dispatch a message handler and it returns negative or a set sd_bus_error
we send this as message error back to the client. This means errors
returned by handlers by default are given back to clients instead of
rippling all the way up to the event loop, which is desirable to make
things robust.

As a side-effect we can now easily turn the SELinux checks into normal
function calls, since the method call dispatcher will generate the right
error replies automatically now.

Also, make sure we always pass the error structure to all property and
method handlers as last argument to follow the usual style of passing
variables for return values as last argument.
2013-11-21 21:12:36 +01:00
Lennart Poettering 9588bc3209 Remove dead code and unexport some calls
"make check-api-unused" informs us about code that is not used anymore
or that is exported but only used internally. Fix these all over the
place.
2013-11-08 18:12:45 +01:00
Lennart Poettering cc37738108 logind: port logind to libsystemd-bus 2013-11-05 01:13:05 +01:00
David Herrmann 92432fcc7f logind: rename vtconsole to seat0
The seat->vtconsole member always points to the default seat seat0. Even
if VTs are disabled, it's used as default seat. Therefore, rename it to
seat0 to correctly state what it is.

This also changes the seat files in /run from IS_VTCONSOLE to IS_SEAT0. It
wasn't used by any code, yet, so this seems fine.

While we are at it, we also remove every "if (s->vtconsole)" as this
pointer is always valid!
2013-09-17 13:47:19 -05:00
David Herrmann e8b212fe56 logind: add infrastructure to watch busnames
If we want to track bus-names to allow exclusive resource-access, we need
a way to get notified when a bus-name is gone. We make logind watch for
NameOwnerChanged dbus events and check whether the name is currently
watched. If it is, we remove it from the watch-list (notification for
other objects can be added in follow-up patches).
2013-09-17 11:30:44 -05:00
David Herrmann 718d006a63 logind: listen actively for session devices
Session compositors need access to fbdev, DRM and evdev devices if they
control a session. To make logind pass them to sessions, we need to
listen for them actively.

However, we avoid creating new seats for non master-of-seat devices. Only
once a seat is created, we start remembering all other session devices. If
the last master-device is removed (even if there are other non-master
devices still available), we destroy the seat. This is the current
behavior, but we need to explicitly implement it now as there may be
non-master devices in the seat->devices list.

Unlike master devices, we don't care whether our list of non-master
devices is complete. We don't export this list but use it only as cache if
sessions request these devices. Hence, if a session requests a device that
is not in the list, we will simply look it up. However, once a session
requested a device, we must be notified of "remove" udev events. So we
must link the devices somehow into the device-list.

Regarding the implementation, we now sort the device list by the "master"
flag. This guarantees that master devices are at the front and non-master
devices at the tail of the list. Thus, we can easily test whether a seat
has a master device attached.
2013-09-17 11:15:29 -05:00
Lennart Poettering 405e0255d5 logind: restore logic to kill user processes when session ends 2013-08-13 17:59:28 +02:00
Lennart Poettering 7fb3ee51c1 user-sessions: rely on PID 1 to kill sessions
As we want to centralized cgroup access we should stop killing the user
sessions directly from the systemd-user-sessions service. Instead, rely
on PID 1 doing this by adding the right ordering dependencies to the
session scope units.
2013-07-10 23:41:04 +02:00
Lennart Poettering 1ee306e124 machined: split out machine registration stuff from logind
Embedded folks don't need the machine registration stuff, hence it's
nice to make this optional. Also, I'd expect that machinectl will grow
additional commands quickly, for example to join existing containers and
suchlike, hence it's better keeping that separate from loginctl.
2013-07-02 03:47:23 +02:00
Lennart Poettering fb6becb443 logind: port over to use scopes+slices for all cgroup stuff
In order to prepare things for the single-writer cgroup scheme, let's
make logind use systemd's own primitives for cgroup management.

Every login user now gets his own private slice unit, in which his sessions
live in a scope unit each. Also, add user@$UID.service to the same
slice, and implicitly start it on first login.
2013-07-02 01:48:55 +02:00
Lennart Poettering 9444b1f20e logind: add infrastructure to keep track of machines, and move to slices
- This changes all logind cgroup objects to use slice objects rather
  than fixed croup locations.

- logind can now collect minimal information about running
  VMs/containers. As fixed cgroup locations can no longer be used we
  need an entity that keeps track of machine cgroups in whatever slice
  they might be located. Since logind already keeps track of users,
  sessions and seats this is a trivial addition.

- nspawn will now register with logind and pass various bits of metadata
  along. A new option "--slice=" has been added to place the container
  in a specific slice.

- loginctl gained commands to list, introspect and terminate machines.

- user.slice and machine.slice will now be pulled in by logind.service,
  since only logind.service requires this slice.
2013-06-20 03:49:59 +02:00
Lennart Poettering 314b4b0a68 logind: rework delay inhibition logic
- Don't allow any locks to be taken while we are in the process of
  executing the specific operation, so that apps are not surprised if a
  suspend/shutdown happens while they rely on their inhibitor.

- Get rid of the Resumed signal, it was a bad idea, and redundant due to
  PrepareForSleep(false), see below.

- Always send out PrepareFor{Shutdown,Sleep} signals, instead of only if
  a delay lock is taken.

- Move PrepareForSleep(false) after we come back from the suspend, so
  that apps can use this as "Resumed" notification. This also has the
  benefit that apps know when to take a new lock.
2013-01-25 06:30:23 +01:00
Lennart Poettering ee17c9281d logind: send Resumed() signal after we come back from suspend/hibernate/hybrid-sleep
This allows clients to get asynchronous notifications for user-requested
suspend/hibernate cycles. Kernel-triggered automatic suspending is not
covered.
2013-01-24 05:15:36 +01:00
Lennart Poettering af9792ac7f logind: only allow one shutdown/sleep action to be queued at the same time
This should make sure that closing the lid while shutting down won't
suspend the machine but will simply cause the shutdown to complete.
2013-01-24 04:56:44 +01:00
Lennart Poettering 23406ce58a logind: add support for automatic suspend/hibernate/shutdown on idle 2012-12-24 00:29:40 +01:00
Lennart Poettering 8e7fd6ade4 logind: split up HandleSleepKey= into HandleSuspendKey= and HandleHibernateKey=
The kernel and X11 distuingish these two, and Thinkpad keys have both,
hence we really should distinguish them too.
2012-09-21 15:44:14 +02:00
Lennart Poettering beaafb2ea6 logind: rework power key/suspend key/lid switch handling
http://lists.freedesktop.org/archives/systemd-devel/2012-September/006604.html
https://bugzilla.gnome.org/show_bug.cgi?id=680689

This changes the meaning of the
HandlePowerKey=/HandleSleepKey=/HandleLidSwitch= setting of logind.conf
2012-09-19 13:10:10 +02:00
Lennart Poettering 98a77df5fe logind: make sure there's always a getty available on TTY6
Previously, if X allocated all 6 TTYs (for multi-session for example) no
getty would be available anymore to guarantee console-based logins.

With the new ReserveVT= switch in logind.conf we can now choose one VT
(6 by default) that will always be subject to autovt-style activation,
i.e. we'll always have a getty on TTY6, and X will never take possession
of it.
2012-09-17 12:39:16 +02:00
Shawn Landden c2f1db8f83 use #pragma once instead of foo*foo #define guards
#pragma once has been "un-deprecated" in gcc since 3.3, and is widely supported
in other compilers.

I've been using and maintaining (rebasing) this patch for a while now, as
it annoyed me to see #ifndef fooblahfoo, etc all over the place,
almost arrogant about the annoyance of having to define all these names to
perform a commen but neccicary functionality, when a completely superior
alternative exists.

I havn't sent it till now, cause its kindof a style change, and it is bad
voodoo to mess with style that has been established by more established
editors. So feel free to lambast me as a crazy bafoon.

v2 - preserve externally used headers
2012-07-19 12:30:59 +02:00
Lennart Poettering 8c8c43515c logind: properly clean up user cgroups when they run empty 2012-05-31 19:46:42 +02:00
Lennart Poettering 069cfc85f8 logind: optionally handle power, sleep and lid switch events
This takes handling of chassis power and sleep keys as well as the lid
switch over from acpid.

This logic is enabled by default for power and sleep keys, but not for
the lid switch.

If a graphical session is in the foreground no action is taken under the
assumption that the graphical session does this.
2012-05-30 15:01:51 +02:00
Lennart Poettering d889a2069a logind: implement suspend/hibernate calls with inhibition logic 2012-05-08 19:02:25 +02:00
Lennart Poettering eecd1362f7 logind: implement delay inhibitor locks in addition to block inhibitor locks
This is useful to allow applications to synchronously save data before
the system is suspended or shut down.
2012-05-05 00:36:08 +02:00