Commit Graph

310 Commits

Author SHA1 Message Date
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Zbigniew Jędrzejewski-Szmek 124d7cb2a0 logind: linewrap some long lines and remove unnecessary conditional 2019-04-07 21:48:54 +02:00
Zbigniew Jędrzejewski-Szmek 6e5dcce4b1 Voidify more mkdir_p calls 2019-03-27 11:53:12 +01:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Vesa Jääskeläinen 428b296a59 logind: Add support for RebootParameter
This adds support for user to set & get reboot parameter for reboot.

As callee would be next issuing Reboot call same policy checks are being used.

If unit file issuing the reboot action defines RebootArgument (or similar) that
setting takes precedence.
2019-03-22 20:30:33 +02:00
Vesa Jääskeläinen ce7f10707d logind: relocate function return_test_polkit()
Relocate function return_test_polkit() upper in file for easier access from other functions.
2019-03-22 17:38:54 +02:00
Topi Miettinen ebcf697685 tree-wide: fix false search hits with ppp (typos) 2019-03-18 14:25:56 +01:00
Lennart Poettering cc5957dca0 bootspec: don't log in boot_entries_load_config_auto() about no ESP
Let's do it in the caller instead. That way, logind can stay silent
about it.

Fixes: #11950
2019-03-13 17:06:24 +01:00
Lennart Poettering f3b5c814ab login: drop redundant newline 2019-03-12 16:10:55 +01:00
Lennart Poettering 350f9518ac logind: refactor logic of returning polkit challenge result into its own function
Let's share some code.
2019-03-05 16:52:46 +01:00
Lennart Poettering 31b221cf5e logind: add support for booting into the boot menu or a specific boot menu entry
This behaves similar to the "boot into firmware" logic, and also allows
either direct EFI operation (which sd-boot supports and others might
support eventually too) or override through env var.
2019-03-05 16:52:46 +01:00
Lennart Poettering e667266a74 logind: optionally support non-EFI reboot-to-firmware
This extends the reboot-to-firmware logic in logind, so that other than
EFI firmwares could be theoretically support. The scheme is like this:
if you want to support this, set the $SYSTEMD_REBOOT_TO_FIRMWARE=1 env
var for logind. If so, this will override the EFI logic, and cause a
file /run/systemd/reboot-to-firmware file to be created when
reboot-to-firmware is requested. This file has no contents, it's mere
existance indicates a reboot with reboot-to-firmware set.

The idea is that for alternative firmwares a drop-in for logind is added
that sets the env var, in combination with some code run during shutdown
that checks for the file and does the right thing.
2019-03-05 16:50:58 +01:00
Yu Watanabe fe3ab8458b login: add a missing error check for session_set_leader()
session_set_leader() may fail. If it fails, then manager_start_scope()
will trigger assertion.

This may be related to RHBZ#1663704.
2019-02-15 11:29:34 +01:00
Yu Watanabe 06c2f0a816 login: simplify the condtion in assertion and slightly decrease binary size 2019-01-08 23:44:50 +09:00
Yu Watanabe 6b9f8b7135 login: use free_and_strdup() at one more place 2019-01-08 23:44:50 +09:00
Yu Watanabe 543680f415 login: adjust range of InhibitWhat in assertions 2019-01-08 23:44:45 +09:00
Yu Watanabe f8bfa31856 login: do not use cast to bool for enum 2019-01-08 02:39:31 +09:00
Zbigniew Jędrzejewski-Szmek 8340b762e4 Revert "sleep: offer hibernation only if the kernel image still exists"
This reverts commit edda44605f.

The kernel explicitly supports resuming with a different kernel than the one
used before hibernation. If this is something that shouldn't be supported, the
place to change this is in the kernel. We shouldn't censor something that this
exclusively in the kernel's domain.

People might be using this to switch kernels without restaring programs, and
we'd break this functionality for them.

Also, even if resuming with a different kernel was a bad idea, we don't really
prevent that with this check, since most users have more than one kernel and
can freely pick a different one from the menu. So this only affected the corner
case where the kernel has been removed, but there is no reason to single it
out.
2018-12-21 18:23:17 +01:00
Yu Watanabe 36dd5ffd5d util: drop missing.h from util.h 2018-12-04 10:00:34 +01:00
Lennart Poettering e4de72876e util-lib: split out all temporary file related calls into tmpfiles-util.c
This splits out a bunch of functions from fileio.c that have to do with
temporary files. Simply to make the header files a bit shorter, and to
group things more nicely.

No code changes, just some rearranging of source files.
2018-12-02 13:22:29 +01:00
Lennart Poettering ee228be10c util-lib: don't include fileio.h from fileio-label.h
There's no reason for doing that, hence simply don't.
2018-12-02 13:22:29 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek 6d176522f5 Revert 5fdf2d51c2
This reverts 5fdf2d51c2, except for one improved
log message.

Fixes #10613.

Checking if resume= is configured is a good idea, but it turns out we cannot do
it reliably:
- the code only supported boot options with sd-boot, and it's not very widely
  used. This means that for most systemd we could only check the current
  commandline, not the next one.
- Various systems resume without, e.g. Debian has
  /etc/initramfs-tools/conf.d/resume in the initramfs.

Making those checks better would be possible with enough effort, but there'll
be always new systems that boot in a slightly different way and we would need
to keep adding new cases. Longer term, we want to rely on autodetecting the
resume partition, and then checks like this will not be necessary at all. It is
quite clear from the number of bug reports that the number of poeple impacted
by this is quite high now, so let's just drop this.
2018-11-21 15:04:22 +01:00
Henry Tung 0c093a62ef logind: fix determination of CanHibernate() and other calls
As suggest here:

https://github.com/systemd/systemd/issues/10250#issuecomment-426788301

Fixes: #10250

(This suggested patch has been converted into a proper commit by me,
Lennart, with attribution to the original author, @henryptung)
2018-11-16 15:52:22 +01:00
Lennart Poettering c57ed5735f logind: log correct error msg 2018-11-16 15:52:22 +01:00
Lennart Poettering 75100aeb9f logind: sort includes 2018-11-16 15:52:22 +01:00
Lennart Poettering 4e96eb682c logind: also expose bool prop on bus that declares whether we are on external power
The three core variables that affect idleness handling are whether we
are docked, whether we are on AC power and whether the lid is closed,
hence let's also expose the third variable on the bus, to make things
nicely debuggable.
2018-11-16 15:39:31 +01:00
Lennart Poettering c30e0d7b6a logind: don't claim that RebootToFirmwareSetup was constant
It's not, after all, that's what SetRebootToFirmware() is about.

(I was wondering for a moment whether to make this EMITS_CHANGES, but
decided against it, given that the flag actually can be changed
externally to logind too, and we couldn't send out notifications for
that.)
2018-11-16 15:39:31 +01:00
Lennart Poettering 9b9c23daf4 logind: expose a boolean on the bus explaining whether logind thinks the lid is closed
This copies how we already expose a "Docked" boolean the reflects
whether we are in a docking station or not.
2018-11-16 15:39:31 +01:00
Yu Watanabe 57512c893e tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files under /proc or /sys 2018-11-06 21:24:03 +09: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 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 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 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 d88ffeeeef logind: correct bad clean-up path 2018-10-13 12:59:29 +02:00
David Tardon e99742ef3e login: avoid leak of name returned by uid_to_name() 2018-10-12 14:51:35 +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
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 4f209af7da logind: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Lennart Poettering edda44605f sleep: offer hibernation only if the kernel image still exists
This makes hibernation unavailable if the kernel image we are currently
running was removed. This is supposed to be superficial protection
against hibernating a system we can never return from because the kernel
has been updated and the kernel we currently run is not available
anymore.

We look at a couple of places for the kernel, which should cover all
distributions I know off. Should I have missed a path I am sure people
will quickly notice and we can add more places to check. (or maybe
convince those distros to stick their kernels at a standard place)
2018-07-26 11:01:29 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 5d904a6aaa tree-wide: drop !! casts to booleans
They are not needed, because anything that is non-zero is converted
to true.

C11:
> 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the
> value compares equal to 0; otherwise, the result is 1.

https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c
2018-06-13 10:52:40 +02:00
Zbigniew Jędrzejewski-Szmek a1230ff972 basic/log: add the log_struct terminator to macro
This way all callers do not need to specify it.
Exhaustively tested by running test-log under valgrind ;)
2018-06-04 13:46:03 +02:00
Lennart Poettering a7b46b7d72 logind: let's change the type of the runtime directory size to uint64_t
Externally it's an uint64_t anyway, and internally we most just
initialize it to physical_memory() which returns uint64_t, hence there's
exactly zero value in using it as size_t internally. Hence, let's fix
that, and use uint64_t everywhere.
2018-05-24 12:14:48 +02:00
Yu Watanabe 01adcd691d login: use BUS_DEFINE_PROPERTY_GET* macros 2018-05-15 23:07:02 +09:00
Yu Watanabe 6e78fa4afd login: do not wall message on cancelling shutdown when Manager.enable_wall_messages is false
Fixes #8904.
2018-05-07 10:17:58 +09:00