Commit Graph
193 Commits
Author SHA1 Message Date
Daan De Meyer d5c12da904 efivars: Remove STRINGIFY() helper macros
The names of these conflict with macros from efi.h that we'll move
to efi-fundamental.h in a later commit. Let's avoid the conflict by
getting rid of these helpers. Arguably this also improves readability
by clearly indicating we're passing arbitrary strings and not constants
to the macros when we invoke them.
2024-11-02 23:20:57 +01:00
Marc Reisner 2d00f4c306 sleep: add HibernateOnACPower= option (#33846)
* Add HibernateOnACPower= systemd-sleep configuration option
2024-08-05 00:01:34 +01:00
Mike Yuan b1ed7e6749 sleep,home: always initialize UnitFreezer if used
Previously, unit_freezer_new_freeze() would only return
UnitFreezer object if FreezeUnit() succeeds. This is not
ideal though, as a failed bus call doesn't mean the action
actually failed. E.g. a timeout might occur because pid1
is waiting for cgroup event from kernel, while the bus call
timeout was exceeded (#33269). In such a case, ThawUnit()
will never be called, resulting in frozen units remain that
way after resuming from sleep.

Therefore, let's get rid of unit_freezer_new_freeze(),
and make sure as long as unit freezer is involved, we'll
call ThawUnit() when we're done. This should make things
a lot more robust.
2024-07-17 18:14:33 +02:00
Mike Yuan 1b5caddfee sleep: also log about errno when getenv_bool fails 2024-07-17 18:14:33 +02:00
Mike Yuan a99935557a sleep: explicitly list valid sleep operations in switch
To follow our usual coding style.
2024-07-17 18:14:32 +02:00
Lennart Poettering be5bee2a13 tree-wide: port over to new builder apis 2024-06-19 22:50:02 +02:00
Lennart Poettering 309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Mike Yuan 61fbc58c46 sleep,home: clean up logs for session freezer a bit 2024-05-30 21:51:48 +08:00
Mike Yuan 12904d5387 bus-unit-util: rework UnitFreezer, explicitly thaw unit
Currently, we don't explicitly call unit_freezer_thaw(),
but rely on the destructor to thaw the frozen unit on
return. This has several problems though, one of them
being that we ignore the return value of ThawUnit(),
which is something we really shouldn't do here,
since such failure can easily leave the whole system
in unusable state. Moreover, the logging is kinda messy,
e.g. homed might log "Everything completed" yet immediately
followed by "Failed to thaw unit". Instead, we should log
consistently and at higher level, to make things more
debuggable.

Therefore, let's step away from the practice. Plus,
make UnitFreezer object heap-allocated, to match
with existing unit_freezer_new() and allow us to
use NULL to denote that the freezer is disabled.
2024-05-30 21:51:48 +08:00
Yu Watanabe 4e494e6aac tree-wise: several cleanups for logging
- drop unnecessary SYNTHETIC_ERRNO() when the logger does not propagate
  error code,
- drop unnecessary '%m' in error message when the error code is
  specified with SYNTHETIC_ERRNO(),
- add missing full stop at the end of log message,
- use RET_GATHER(),
- add missing ", ignoring.",
- upeercase the first letter, etc., etc...
2024-05-01 04:41:06 +09:00
Mike Yuan 36b21fac8f sleep: rename SleepMemMode= to MemorySleepMode=
Addresses https://github.com/systemd/systemd/pull/31986#discussion_r1554053623
2024-04-06 02:16:54 +08:00
Mike Yuan fbc88824b6 hibernate-util: make clear_efi_hibernate_location_and_warn return 1 if
actually cleared the variable
2024-04-03 21:59:59 +08:00
Mike Yuan a2124b35e9 sleep: add SleepMemMode= setting for configuring /sys/power/mem_sleep
The setting is used when /sys/power/state is set to 'mem'
(common for suspend) or /sys/power/disk is set to 'suspend'
(hybrid-sleep). We default to kernel choice here, i.e.
respect what's set through 'mem_sleep_default=' kernel
cmdline option.
2024-03-28 17:19:35 +08:00
Mike Yuan b786128322 sleep: make write_mode take a path
Similar to the previous commit, preparation
for adding support for /sys/power/mem_sleep.
2024-03-28 17:16:25 +08:00
Mike Yuan 792dd6f46c sleep-config: make sleep_operation_is_hibernation uppercase 2024-03-28 17:16:21 +08:00
Mike Yuan 45df233e5f sleep: fix typo (sysupend -> suspend) 2024-03-08 01:10:10 +08:00
Adrian Vovk 0b958bb3ee sleep: Always freeze user.slice
Previously, we'd only freeze user.slice in the case of s2h, because we
didn't want the user session to resume while systemd was transitioning
from suspend to hibernate.

This commit extends this freezing behavior to all sleep modes.

We also have an environment variable to disable the freezing behavior
outright. This is a necessary workaround for someone that has hooks
in /usr/lib/systemd/system-sleep/ which communicate with some
process running under user.slice, or if someone is using the proprietary
NVIDIA driver which breaks when user.slice is frozen (issue #27559)

Fixes #27559
2024-03-05 12:12:35 -05:00
Mike Yuan 4f49512695 extract-word: modernize extract_many_words 2024-03-03 19:01:00 +08:00
Lennart Poettering e7be86519d sleep: upgrade fatal log message to LOG_ERR 2024-01-30 11:32:56 +01:00
Lennart Poettering 75d2752814 sleep: upgrade some unexpected errors to LOG_WARNING log messages 2024-01-30 11:32:41 +01:00
Lennart Poettering b782080b7a sleep: remove redundant debug log message 2024-01-30 11:31:56 +01:00
Lennart Poettering 032bf2da46 sleep: add mising error message 2024-01-30 11:31:36 +01:00
Mike Yuan fe33920c2a sleep: don't log duplicate error
write_resume_config() logs error on its own.
2023-12-27 22:38:43 +08:00
Mike Yuan e14348c616 sleep: connect to correct bus when locking homed-managed homes
Partially reverts 122f6f1eaa

Fixes https://github.com/systemd/systemd/issues/29938#issuecomment-1869508708
2023-12-26 18:53:03 +01:00
Yu Watanabe c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Mike Yuan 8ad973ed99 hibernate-util: de-duplicate clear_efi_hibernate_location 2023-12-10 14:08:46 +09:00
Mike Yuan 1fe536aa37 sleep: reduce the scope of hibernation_device 2023-12-05 16:52:19 +08:00
Mike Yuan cc1c8d129f sleep: make sure we clear HibernateLocation on all error paths
Also, let's say "sleep operation" rather than "sleep state",
the latter of which creates ambiguity with /sys/power/state.
2023-10-28 00:17:15 +08:00
Mike Yuan 122f6f1eaa sleep: minor modernization for lock_all_homes 2023-10-27 18:11:32 +08:00
Mike Yuan 78c21009bf sleep: rework write_state and write_mode 2023-10-27 18:11:29 +08:00
Mike Yuan 0374cbd668 sleep: update help text for suspend-then-hibernate 2023-10-27 17:57:03 +08:00
Mike Yuan 4706c3ec2b sleep: log about errno 2023-10-27 17:57:03 +08:00
Mike Yuan 37f80890b2 sleep: drop unneeded includes 2023-10-27 17:57:03 +08:00
Mike Yuan e024cdd270 sleep: introduce sleep_operation_is_hibernation 2023-10-27 17:57:03 +08:00
Mike Yuan 828ad30470 sleep-config: make hybrid sleep always use 'suspend' disk mode
If user requests hybrid sleep, we should always use 'suspend'
disk mode. If that's not supported, let's correctly report it
so they can choose plain hibernation instead. HybridSleepMode=
serves no purpose in this case and should be removed.

Addresses https://github.com/systemd/systemd/pull/29681#discussion_r1369812785
2023-10-24 19:07:03 +02:00
Mike Yuan 1f82c21dce sleep-config: remove HibernateState= & HybridSleepState=, restrict
SuspendState= not to include "disk"

I don't know why these existed in the first place, but as I
justified in the comments, it's simply not sensible to allow
HibernateState= or HybridSleepState= to take values other than
'disk'. So let's just remove those options. Also, SuspendState=
should not contain 'disk'.
2023-10-23 23:12:27 +08:00
Mike Yuan 596873c10c hibernate-util: rework find_hibernate_location
* "HibernateLocation" struct is renamed to HibernationDevice
  to avoid ambiguity with the EFI variable. Also, it no longer
  takes the reference to a SwapEntry object, since it's really
  unnecessary (only SwapEntry.path is used), but increases complexity.
* SwapEntry is no longer used externally.
* find_hibernate_location is split into read_swap_entries and
  find_suitable_hibernation_device. The former reads all swap entries
  into SwapEntries object for later use.
* Make use of btrfs_get_file_physical_offset_fd

Closes #25130
2023-10-20 23:22:54 +08:00
Franck Bui 6495361c7d meson: add build option for install path of main config files
This allows distros to install configuration file templates in /usr/lib/systemd
for example.

Currently we install "empty" config files in /etc/systemd/. They serve two
purposes:

- The file contains commented-out values that show the default settings.
- It is easier to edit the right file if it is already there, the user doesn't
  have to type in the path correctly, and the basic file structure is already in
  place so it's easier to edit.

Things that have happened since this approach was put in place:

- We started supporting drop-ins for config files, and drop-ins are the
  recommended way to create local configuration overrides.
- We have systemd-analyze cat-config which takes care of iterating over
  all possible locations (/etc, /run, /usr, /usr/local) and figuring out
  the right file.
- Because of the first two points, systemd-analyze cat-config is much better,
  because it takes care of finding all the drop-ins and figuring out the
  precedence. Looking at files manually is still possible of course, but not
  very convenient.

The disadvantages of the current approach with "empty" files in /etc:

- We clutter up /etc so it's harder to see what the local configuration actually is.
- If a user edits the file, package updates will not override the file (e.g.
  systemd.rpm uses %config(noreplace). This means that the "documented defaults"
  will become stale over time, if the user ever edits the main config file.

Thus, I think that it's reasonable to:

- Install the main config file to /usr/lib so that it serves as reference for
  syntax and option names and default values and is properly updated on package
  upgrades.
- Recommend to users to always use drop-ins for configuration and
  systemd-analyze cat-config to view the documentation.

This setting makes this change opt-in.

Fixes #18420.

[zjs: add more text to the description]
2023-10-17 18:57:45 +02:00
Zbigniew Jędrzejewski-Szmek ee691c802b Merge pull request #29242 from fbuihuu/update-main-config-file-headers
config files: update their header to reflect that they can be install…
2023-10-17 18:56:09 +02:00
Mike Yuan 087a25d2ca sleep-config: several cleanups
* Rename free_sleep_config to sleep_config_free
* Rearrange functions
* Make SleepConfig.modes and .states only contain
  operations that needs configuration
* Add missing assert
2023-09-27 21:48:39 +08:00
Mike Yuan f3afe9dc20 sleep/battery-capacity: rearrange functions 2023-09-27 21:48:39 +08:00
Mike Yuan 7f88eee935 sleep/battery-capacity: drop unused error-handling 2023-09-27 21:48:39 +08:00
Mike Yuan fbc1dbf296 sleep/battery-capacity: don't report we have trip alarm if no battery is found 2023-09-27 21:48:39 +08:00
Mike Yuan 54d7fcc6a3 sleep-util: split into sleep-config and hibernate-util 2023-09-27 21:48:39 +08:00
Mike Yuan 7d769198e0 sleep-util: split battery-capacity into sleep/
This is only used by sleep.c. Let's start shrinking down
the "mixed" sleep-util.
2023-09-27 21:48:39 +08:00
Mike Yuan 43309f14d9 sleep: rebreak lines in check_wakeup_type 2023-09-27 21:48:39 +08:00
Mike Yuan 1482feda01 sleep-util: move check_wakeup_type to sleep/sleep 2023-09-27 21:48:39 +08:00
Franck Bui c60801738c config files: update their header to reflect that they can be installed in /usr
Follow-up for c76f2fb0e5.
2023-09-21 18:54:39 +02:00
Franck Bui 58849483a4 config files: more recommendations of systemd-analyze cat-config
Follow-up for 3b0754b16c.
2023-09-19 17:47:57 +02:00
Mike Yuan 031a399d87 sleep: clear EFI HibernateLocation if writing kernel config fails
Follow-up for f1f331a252
2023-08-13 22:12:32 +01:00