summaryrefslogtreecommitdiff
path: root/src/sleep
Commit message (Collapse)AuthorAgeFilesLines
* tre-wide: use FORMAT_DEVNUM() a bit moreLennart Poettering2023-04-211-2/+4
|
* sleep: fix default values unmatched with manualMike Yuan2023-03-181-1/+4
|
* sleep: check if we're on AC power before checking battery capacityMike Yuan2023-02-211-1/+1
| | | | | | | | | | Before this commit, battery_is_low() returns true if there's no battery on the system. It's now modified to check if the system is on AC power first, and returns false early if that's the case. Fixes #26492
* sleep: use shared constant for freeze timeoutZbigniew Jędrzejewski-Szmek2023-02-201-2/+1
| | | | Let's keep all the timeout definitions in one place.
* sleep: coding style fixletsYu Watanabe2023-01-271-2/+2
|
* sleep: introduce SuspendEstimationSec=Yu Watanabe2023-01-272-15/+36
| | | | | | | | | | | | | | | | | | | Before v252, HibernateDelaySec= specifies the maximum timespan that the system in suspend state, and the system hibernate after the timespan. However, after 96d662fa4c8cab24da57523c5e49e6ef3967fc13, the setting is repurposed as the default interval to measure battery charge level and estimate the battery discharging late. And if the system has enough battery capacity, then the system will stay in suspend state and not hibernate even if the time passed. See issue #25269. To keep the backward compatibility, let's introduce another setting SuspendEstimationSec= for controlling the interval to measure battery charge level, and make HibernateDelaySec= work as of v251. This also drops implementation details from the man page. Fixes #25269.
* sleep: drop unnecessary temporal vaiable and initializationYu Watanabe2023-01-261-5/+6
|
* sleep: fetch_batteries_capacity_by_name() does not return -ENOENTYu Watanabe2023-01-261-13/+13
|
* sleep: rename hibernate_delay_sec -> _usecYu Watanabe2023-01-261-1/+1
|
* sleep: fix memleakZbigniew Jędrzejewski-Szmek2023-01-231-1/+1
| | | | | | Those hashmaps are created anew in each iteration of the loop. The leak wasn't really a problem, because the loop is bounded and the hashmaps were not huge, but it's nicer to be correct.
* sleep: reduce double logging and improve messages and comments a bitZbigniew Jędrzejewski-Szmek2023-01-231-1/+2
| | | | | | | | | | | read_battery_capacity_percentage() was already logging, but with a slightly different wording. More could be done, I just touched the most noticable places. Especially in debug messages, it is much more useful to be direct about what couldn't be accessed or parsed, instead of providing "descriptive names" which are not useful to the user at all, who then needs to read the code to figure out what was the actual property name.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* core/sleep: set timeout for freeze/thaw operation to 1.5 secondsmsizanoen12022-12-081-0/+3
| | | | | | | A FreezeUnit operation can hang due to the presence of kernel threads (see last 2 commits). Keeping the default configuration will mean the system will hang for 25 seconds in suspend waiting for the response. 1.5 seconds should be sufficient for most cases.
* sleep: always thaw user.slice even if freezing failedmsizanoen12022-12-081-3/+1
| | | | | | `FreezeUnit` can fail even when some units did got frozen, causing some user units to be frozen. A possible symptom is `user@.service` being frozen while still being able to log in over SSH.
* Rename def.h to constants.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
| | | | | | The name "def.h" originates from before the rule of "no needless abbreviations" was established. Let's rename the file to clarify that it contains a collection of various semi-related constants.
* basic: move version() to build.h+cZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
|
* sleep: freeze and thaw user.slice to save resource while suspendSonali Srivastava2022-08-261-0/+31
|
* sleep: support acpi_btp and suspend system if enabled, skipping custom timerSonali Srivastava2022-08-231-1/+49
|
* sleep: support multiple battery instead of only BAT0Sonali Srivastava2022-08-091-39/+25
|
* tree-wide: fix typoYu Watanabe2022-08-021-1/+1
|
* sleep: store battery discharge rate/hour with hashSonali Srivastava2022-07-201-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Estimated battery discharge rate per hour is stored in : /var/lib/systemd/sleep/battery_discharge_percentage_rate_per_hour This value is used to determine the initial suspend interval. In case this file is not available or value is invalid, HibernateDelaySec interval is used. After wakeup from initial suspend, this value is again estimated and written to file if value is in range of 1-199. Logs for reference : HibernateDelaySec=15min - Updated in /etc/systemd/sleep.conf Jul 14 19:17:58 localhost systemd-sleep[567]: Current battery charge percentage: 100% Jul 14 19:17:58 localhost systemd-sleep[567]: Failed to read discharge rate from /var/lib/systemd/sleep/batt ery_discharge_percentage_rate_per_hour: No such file or directory Jul 14 19:17:58 localhost systemd-sleep[567]: Set timerfd wake alarm for 15min Jul 14 19:33:00 localhost systemd-sleep[567]: Current battery charge percentage after wakeup: 90% Jul 14 19:33:00 localhost systemd-sleep[567]: Attempting to estimate battery discharge rate after wakeup from 15min sleep Jul 14 19:33:00 localhost systemd-sleep[567]: product_id does not exist: No such file or directory Jul 14 19:33:00 localhost systemd-sleep[567]: Estimated discharge rate 39 successfully updated to /var/lib/systemd/sleep/battery_discharge_percentage_rate_per_hour Jul 14 19:33:00 localhost systemd-sleep[567]: Current battery charge percentage: 90% Jul 14 19:33:00 localhost systemd-sleep[567]: product_id does not exist: No such file or directory Jul 14 19:33:00 localhost systemd-sleep[567]: Set timerfd wake alarm for 1h 48min 27s Jul 14 21:21:30 localhost systemd-sleep[567]: Current battery charge percentage after wakeup: 90% Jul 14 21:21:30 localhost systemd-sleep[567]: Battery was not discharged during suspension
* sleep: use current charge level to decide suspensionSonali Srivastava2022-07-201-28/+63
| | | | | | | If battery current charge percentage is below 5% hibernate directly. Else initial suspend interval is set for HibernateDelaySec. On wakeup estimate battery discharge rate per hour and if battery charge percentage is not below 5% system is suspended else hibernated.
* Update sleep.conf HibernateDelaySec default to match implementationRichard Huang2022-07-181-1/+1
|
* tree-wide: Remove the repeated ';' from code (#23901)Li kunyu2022-07-051-1/+1
|
* tree-wide: add a space after if, switch, for, and whileYu Watanabe2022-04-011-1/+1
|
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-2/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-1/+1
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* tree-wide: add FORMAT_TIMESPAN()Zbigniew Jędrzejewski-Szmek2021-07-091-3/+2
|
* sleep: clarify that failure setting env var is not fatalLennart Poettering2021-05-221-1/+1
|
* sleep: if hybrid sleep fails, do regular suspendLennart Poettering2021-05-221-4/+26
| | | | Fixes #19550
* sleep: remove duplicate loggingLennart Poettering2021-05-221-2/+2
| | | | | execute() logs about all errors, hence only log about what's new, i.e. what we'll do as consequence, and don't mention the error cause again.
* sleep: use SleepOperation enum everywhere and drop sleep_settings()Lennart Poettering2021-05-221-33/+46
| | | | | | | | | Instead of comparing strings everywhere, let's use the new enum. This allows us to drop sleep_settings(), since the operation enum can be directly used as index into the config settings. Some minor other refactoring is done, but mostly just shifting thing around a bit, no actual change in behaviour.
* fix: point to the correct drop-ins subdirectory for confsJóhann B. Guðmundsson2021-04-221-1/+1
|
* Do not try to return 0 from log_debug()Zbigniew Jędrzejewski-Szmek2021-04-141-4/+4
| | | | | | | | | As @yuwata correctly points out, this became broken when log_debug() started returning -EIO. I wanted to preserve this pattern, but it turns out it is not very widely used, and preserving it would make the whole thing, already quite complicated, even more complex. log_debug() is made like log_info() and friends, and returns void.
* Recommend drop-ins over modifications to the main config fileZbigniew Jędrzejewski-Szmek2021-02-191-8/+9
| | | | As discussed in https://github.com/systemd/systemd/pull/18347.
* tree-wide: enable colorized logging for daemons when run in consoleYu Watanabe2021-02-011-1/+1
| | | | It may be useful when debugging daemons.
* tree-wide: Drop custom formatting for print() help messagesDaan De Meyer2021-01-311-4/+3
| | | | | | | | | | | | I think this formatting was originally used because it simplified adding new options to the help messages. However, these days, most tools their help message end with "\nSee the %s for details.\n" so the final line almost never has to be edited which eliminates the benefit of the custom formatting used for printf() help messages. Let's make things more consistent and use the same formatting for printf() help messages that we use everywhere else. Prompted by https://github.com/systemd/systemd/pull/18355#discussion_r567241580
* systemd-sleep: Set SYSTEMD_SLEEP_ACTION for systemd-sleep hooks.Zach Smith2021-01-091-5/+9
| | | | | | | | | When suspend-then-hibernate is called, hooks have no ability to determine which stage of the request is being handled; they only see 'pre' and 'post' with the verb 'suspend-then-hibernate'. This change introduces an environment variable called SYSTEMD_SLEEP_ACTION that contains the name of the action that is processing: 'suspend', 'hibernate', 'hybrid-sleep', or 'suspend-after-failed-hibernate'.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* sleep: reword some debug messagesZbigniew Jędrzejewski-Szmek2020-09-081-5/+4
| | | | I think the sentences sound more natural this way.
* various: treat BUS_ERROR_NO_SUCH_UNIT the same as SD_BUS_ERROR_SERVICE_UNKNOWNZbigniew Jędrzejewski-Szmek2020-08-241-5/+2
| | | | | | | | | | | | | | | | We return BUS_ERROR_NO_SUCH_UNIT a.k.a. org.freedesktop.systemd1.NoSuchUnit in various places. In #16813: Aug 22 06:14:48 core sudo[2769199]: pam_systemd_home(sudo:account): Failed to query user record: Unit dbus-org.freedesktop.home1.service not found. Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.home1.service': Unit dbus-org.freedesktop.home1.service not found. Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activating via systemd: service name='org.freedesktop.home1' unit='dbus-org.freedesktop.home1.service' requested by ':1.6564' (uid=0 pid=2769199 comm="sudo su ") This particular error comes from bus_unit_validate_load_state() in pid1: case UNIT_NOT_FOUND: return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not found.", u->id); It seems possible that we should return a different error, but it doesn't really matter: if we change pid1 to return a different error, we still need to handle BUS_ERROR_NO_SUCH_UNIT as in this patch to handle pid1 with current code.
* sleep: one spelling unificationZbigniew Jędrzejewski-Szmek2020-07-071-1/+1
| | | | We use "writable" everywhere else.
* sleep: pass error we see to log functionLennart Poettering2020-06-111-2/+5
|
* sleep: clean up debug/error loggingLennart Poettering2020-06-111-3/+5
| | | | | | | | | 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.
* tree-wide: port to fd_wait_for_event()Lennart Poettering2020-06-101-18/+9
| | | | | | | | Prompted by the discussion on #16110, let's migrate more code to fd_wait_for_event(). This only leaves 7 places where we call into poll()/poll() directly in our entire codebase. (one of which is fd_wait_for_event() itself)
* tree-wide: check POLLNVAL everywhereLennart Poettering2020-06-101-0/+3
| | | | | | | | | | | | | poll() sets POLLNVAL inside of the poll structures if an invalid fd is passed. So far we generally didn't check for that, thus not taking notice of the error. Given that this specific kind of error is generally indication of a programming error, and given that our code is embedded into our projects via NSS or because people link against our library, let's explicitly check for this and convert it to EBADF. (I ran into a busy loop because of this missing check when some of my test code accidentally closed an fd it shouldn't close, so this is a real thing)
* sleep: automatically lock all home directories when suspendingLennart Poettering2020-01-281-1/+46
|
* systemd-sleep: always attempt hibernation if configuredZach Smith2020-01-051-7/+8
| | | | | | | | 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.
* tree-wide: drop stdio.h when stdio-util.h is includedYu Watanabe2019-11-041-1/+0
|
* systemd-sleep: always prefer resume device or fileZach Smith2019-10-241-81/+30
| | | | | | | 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.