summaryrefslogtreecommitdiff
path: root/src/sleep
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* systemd-sleep: refuse to calculate swapfile offset on BtrfsZach Smith2019-06-261-1/+9
| | | | | | | | | | If hibernation is requested but /sys/power/resume and /sys/power/resume_offset are not configured correctly, systemd-sleep attempts to calculate swapfile offset using fstat and fiemap. Btrfs returns virtual device number for stat and a virtual offset for fiemap which results in incorrect offset calculations. In the case where offset would be calculated and the user is using Btrfs, log a debug message and fail to write device and offset values.
* systemd-sleep: (bug) use resume_offset value if setZach Smith2019-06-261-2/+34
| | | | | | | 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
* sleep: properly pass verb to sleep scriptLennart Poettering2019-06-171-1/+5
| | | | | | Another fall-out from our rewriting of argv[] now. Fixes: #12782
* systemd-sleep: refactor sleep config parsingZach Smith2019-05-301-20/+17
| | | | | | | | remove verb from parse refactor required fields checks refactor allow settings
* systemd-sleep: replace rtc wakealarm with CLOCK_BOOTTIME_ALARM s2hZach Smith2019-05-281-46/+26
| | | | | | | | | | 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
* fix typo in partition device messageZach Smith2019-05-141-1/+1
|
* headers: remove unneeded includes from util.hZbigniew Jędrzejewski-Szmek2019-03-271-0/+5
| | | | | 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.
* sleep: (void)ify some callLennart Poettering2019-03-261-2/+2
|
* core: Allow to configure execute_directories execution behaviorMatthias Klumpp2019-02-181-2/+2
| | | | | | | | | This adds a new bitfield to `execute_directories()` which allows to configure whether to ignore non-zero exit statuses of binaries run and whether to allow parallel execution of commands. In case errors are not ignored, the exit status of the failed script will now be returned for error reposrting purposes or other further future use.
* sleep: install default sleep.confYu Watanabe2019-01-031-0/+25
| | | | Closes #11310.
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-221-21/+17
| | | | | | | | | | | 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.
* Split out pretty-print.c and move pager.c and main-func.h to shared/Zbigniew Jędrzejewski-Szmek2018-11-201-1/+1
| | | | | This is high-level functionality, and fits better in shared/ (which is for our executables), than in basic/ (which is also for libraries).
* log: introduce new helper call log_setup_service()Lennart Poettering2018-11-201-3/+1
| | | | | Let's reduce the common boilerplate and have a single setup function used by all service code to setup logging.
* util-lib: move main() definition macros to its own header fileLennart Poettering2018-11-191-0/+1
| | | | | | | | | This way, we can extend the macro a bit with stuff pulled in from other headers without this affecting everything which pulls in macro.h, which is one of our most basic headers. This is just refactoring, no change in behaviour, in prepartion for later changes.
* sleep: define main through macroZbigniew Jędrzejewski-Szmek2018-11-171-9/+8
|
* tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files ↵Yu Watanabe2018-11-061-6/+8
| | | | under /proc or /sys