Commit Graph

98 Commits

Author SHA1 Message Date
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 12ce0f4173
Merge pull request #16635 from keszybz/do-not-for-each-word
Drop FOREACH_WORD
2020-09-09 17:43:38 +02:00
Lennart Poettering d161680e7a tree-wide: if get_block_device() returns zero devno, check for it in all cases
And add a comment for the existing cases where things aren't clear
already.
2020-09-08 18:10:26 +02:00
Zbigniew Jędrzejewski-Szmek 434fef6de3 shared/sleep-config: more logging and port to extract_first_word() 2020-09-04 13:53:47 +02:00
Zbigniew Jędrzejewski-Szmek c550cb7f8c test-sleep: add more logging, show secure boot mode
In https://bugzilla.redhat.com/show_bug.cgi?id=1858219 a user
reported that hibernation is not supported. This is probably caused
by secure boot, but our current logging does not make this
obvious.
2020-07-29 11:12:13 +02:00
Lennart Poettering 1326de0158 sleep-config: modernize destructors
All other destructors in the same .c file return NULL, let's make sure
the one where this so far wasn't done does it too.
2020-06-11 10:33:57 +02:00
Lennart Poettering c732e87979 sleep-config: downgrade log level in can_s2h()
As in the previous commit: can_sleep() is more a library-style function,
hence log at debug level only.
2020-06-11 10:33:56 +02:00
Lennart Poettering c02540dc9e sleep: clean up debug/error logging
half of find_hibernation_location() logged at debug level, the other
half logged at error level, and the third half didn't log at all.

Let's clean this up somewhat. Since can_sleep() is probably more
a library-style function let's downgrade everything to LOG_DEBUG and
then make sure sleep.c logs at error level, as the main program.
2020-06-11 10:33:56 +02:00
Lennart Poettering 6f9120ad61 sleep-config: return correct error code 2020-06-11 10:33:56 +02:00
Lennart Poettering c0d8fbfa34 sleep-config: add more debug logging 2020-06-11 10:33:56 +02:00
Lennart Poettering 4f9ff96a55 conf-parser: return mtime in config_parse() and friends
This is a follow-up for 9f83091e3c.

Instead of reading the mtime off the configuration files after reading,
let's do so before reading, but with the fd we read the data from. This
is not only cleaner (as it allows us to save one stat()), but also has
the benefit that we'll detect changes that happen while we read the
files.

This also reworks unit file drop-ins to use the common code for
determining drop-in mtime, instead of reading system clock for that.
2020-06-02 19:32:20 +02:00
Zbigniew Jędrzejewski-Szmek 162392b75a tree-wide: spellcheck using codespell
Fixes #15436.
2020-04-16 18:00:40 +02:00
Lennart Poettering 0ed4b54e05 sleep: improve log msg slightly
Let's make the log msgs a bit longer, to make clearer what is going on
here...

Prompted bymy attempts to debug #15354
2020-04-09 10:17:54 +02:00
Zbigniew Jędrzejewski-Szmek 8f817cb888 shared/sleep-config: do not ignore resume_offset when resume not set
This is most likely a user error, let's make it easier to diagnose.
2020-01-08 08:07:14 +01:00
Zbigniew Jędrzejewski-Szmek 8efc2c1608 shared/sleep-config: make swap detection stricter again
To make this easier to understand, let's always log (at debug level)
when we accept or reject each device:
/swapfile: detection of swap file offset on Btrfs is not supported
/swapfile: is a candidate device.
/dev/zram0: ignoring zram swap
/dev/vdb: ignoring device with lower priority
/dev/vdc: ignoring device with lower usable space
...

If we know that hibernation will fail, refuse. This includes cases where
/sys/power/resume is set and doesn't match any device, or
/sys/power/resume_offset is set and we're not on btrfs and it doesn't match.
If /sys/power/resume is not set at all, we still accept the device with the
highest priority (see 6d176522f5 and
88bc86fcf8)

Tested cases:
1. no swap active → refuse
2. just zram swap active → refuse
3. swapfile on btrfs with /sys/power/resume{,_offset} set → OK
4. swapfile on btrfs with /sys/power/resume set, offset not set → refuse
5. swapfile on btrfs with /sys/power/resume set to nonexistent device, offset set → refuse
6. /sys/power/resume not set, offset set, candidate exists → OK (*)
7. /sys/power/resume not set, offset not set, candidate exists → OK

(*) I think this should fail, but I'm leaving that for the next commit.
2020-01-08 08:07:14 +01:00
Zbigniew Jędrzejewski-Szmek e9f0c5d08c shared/sleep: use stat() instead of open()+fstat() in one place
No functional change.
2020-01-07 16:20:35 +01:00
Zach Smith 52133271a7 systemd-sleep: always attempt hibernation if configured
When calculation of swap file offset is unsupported, rely on the
/sys/power/resume & /sys/power/resume_offset values if configured
rather than requiring a matching swap entry to be identified.

Refactor to use dev_t for comparison of resume= device instead of string.
2020-01-05 20:15:38 -08:00
Zbigniew Jędrzejewski-Szmek 5021735fad shared/sleep-config: fix potential SEGV
We were looking at the wrong variable, and would always crash if this
comparison was reached. Fixes #13965.

Also, fix crash (_cleanup_ called on uninitialized variable) if we failed in
error path.

While at it, let's shorten some messages.
2019-11-09 09:19:36 +00:00
Yu Watanabe 1405cb653a tree-wide: drop stdio.h when stdio-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zbigniew Jędrzejewski-Szmek b72571e04d shared/sleep-config: two more error handling fixes, use structured initialization
CID#1406472.
2019-10-25 17:10:47 +02:00
Zbigniew Jędrzejewski-Szmek e97c369153 shared/sleep-config: fix error handling for open
CID#1406472.
2019-10-25 17:03:02 +02:00
Zach Smith ea470720e4 systemd-sleep: improve /proc/swaps open fail message 2019-10-24 07:38:31 -07:00
Zach Smith 7bdf56a28a systemd-sleep: always prefer resume device or file
This change checks each swap partition or file reported in /proc/swaps
to see if it matches the values configured with resume= and
resume_offset= kernel parameters. If a match is found, the matching swap
entry is used as the hibernation location regardless of swap priority.
2019-10-24 07:38:24 -07:00
Zbigniew Jędrzejewski-Szmek df38212dd1
Merge pull request #13212 from poettering/sleep-conf-default
sleep: document default HibernateDelaySec=
2019-07-29 16:03:54 +02:00
Zach Smith 88bc86fcf8 systemd-sleep: use swaps in priority order
In situations where hibernation is requested but resume= and
resume_offset= kernel parameters are not configured, systemd
will attempt to locate a suitable swap location by inspecting
/proc/swaps. This change will use the first suitable swap with
the highest configured priority.
2019-07-29 12:59:17 +02:00
Lennart Poettering a077755abf man: document default HibernateDelaySec= setting 2019-07-29 12:49:38 +02:00
Zach Smith 2002d8cdae systemd-sleep: (bug) use resume_offset value if set
Use hibernation configuration as defined in
/sys/power/resume and /sys/power/resume_offset
if present before inspecting /proc/swaps and
attempting to calculate swapfile offset
2019-06-26 22:04:59 -07:00
Zach Smith 7874583da3 systemd-sleep: (bug) honor s2h and hybrid_sleep disable settings 2019-05-30 06:08:02 -07:00
Zach Smith 28ca9c2499 systemd-sleep: refactor sleep config parsing
remove verb from parse

refactor required fields checks

refactor allow settings
2019-05-30 06:06:16 -07:00
Zach Smith 1bbbefe7a6 systemd-sleep: replace rtc wakealarm with CLOCK_BOOTTIME_ALARM s2h
refactor to use timerfd in place of rtc wakealarm

confirm CLOCK_BOOTTIME_ALARM support in can_s2h

Remove CLOCK_BOOTTIME_ALARM task from TODO

remove unnecessary check on clock_supported return
2019-05-28 17:02:36 +02:00
Zach Smith 45733c9d21 fix typo in wakealarm message 2019-05-13 20:01:36 -07: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
Lennart Poettering 427646ea9d sleep: use negative_errno() where appropriate 2019-03-26 11:17:23 +01: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
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
Lennart Poettering bea1a01310 strv: wrap strv_new() in a macro so that NULL sentinel is implicit 2018-10-31 18:00:52 +01:00
Zbigniew Jędrzejewski-Szmek e8f1d00d69 shared/sleep-config: add switches to kill specific sleep modes
/etc/systemd/sleep.conf gains four new switches:
AllowSuspend=, AllowHibernation=, AllowSuspendThenHibernate=, AllowHybridSleep=.

Disabling specific modes was already possible by masking suspend.target,
hibernate.target, suspend-then-hibernate.target, or hybrid-sleep.target.
But this is not convenient for distributions, which want to set some defaults
based on what they want to support. Having those available as configuration
makes it easy to put a config file in /usr/lib/systemd/sleep.conf.d/ that
overrides the defaults and gives instructions how to undo that override.
2018-10-08 18:21:00 +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
Lennart Poettering 904865b8c2 sleep-config: library code should not log beyond LOG_DEBUG 2018-07-26 11:01:29 +02: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 7474f15b2d sleep-config: eat up errors only after debug logging about them 2018-07-26 11:01:29 +02:00
Lennart Poettering 3dea6886c2 sleep-config: partitions can't be deleted, only files can
This fixes something I think was basically a typo introduced in
db69869f26.
2018-07-26 11:01:29 +02:00
Andrew Jorgensen 411ae92b40 shared/sleep-config: exclude zram devices from hibernation candidates
On a host with sufficiently large zram but with no actual swap, logind will
respond to CanHibernate() with yes. With this patch, it will correctly respond
no, unless there are other swap devices to consider.
2018-07-26 10:19:04 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +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 db983479af shared/sleep-config: fix memleak of strv, add test
CID #1390921, #1390951.
2018-05-10 01:36:50 +02:00