summaryrefslogtreecommitdiff
path: root/src/sleep
Commit message (Collapse)AuthorAgeFilesLines
* 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
* sleep: when we can't hibernate on suspend-then-hibernate, fall back to ↵Lennart Poettering2018-10-241-1/+11
| | | | | | | | | suspend again Let's make this a bit safer, and try hard to return to sleep, if we can at all. Fixes: #10212
* sleep: rework what we do if a suspend fails.Lennart Poettering2018-10-241-6/+9
| | | | | | | | | | | | | | | | | First of all, let's fix logging: let's simply log the same message as we do on success, so that there's always the same pair of these messages around, regardless if the suspend was successful or not. To distuingish a successful suspend from a failed one, check the ERRNO= field of the structured message. In most ways a failed suspend cycle is not distuingishable from a successful one that took no time, hence let's treat it this way, and always pair the success message with a failure message. This also changes a more important concept: the post-suspend callouts are now called also called on failure, following the same logic: let's always run them in pairs: for every pre callout a post callout has to follow.
* sleep: no need to check for resume_offset twiceLennart Poettering2018-10-241-6/+5
| | | | | The W_OK check already checks for existance hence let's remove the F_OK check.
* sleep: let's turn off the RTC alarm time ASAPLennart Poettering2018-10-241-7/+7
| | | | | | | Let's be a tiny bit more careful here. Also, let's rearrange things to simplify them a bit, and to not use "r" outside of its immediate scope of validity.
* sleep: round up when calculating RTC sleep timeLennart Poettering2018-10-241-1/+1
| | | | | Paranoia: this way we know that when we wake up all timers are definitely equal or ahead of what we expect them to be.
* sleep: move log message generation for rtc_read_time() into the function itselfLennart Poettering2018-10-241-4/+8
| | | | | The log messages were petty borked anyway, and generated at two separate locations. Let's fix that.
* sleep: rework write_wakealarm() to take a numeric parameterLennart Poettering2018-10-241-13/+13
| | | | | | Also, let's rename it to rtc_write_wake_alarm(). Both changes together make sure rtc_write_wake_alarm() and rtc_read_time() are more alike in their naming and semantics.
* sleep: rename read_wakealarm() → rtc_read_time()Lennart Poettering2018-10-241-4/+4
| | | | | It doesn't read wakealarm, but the current time of the RTC. Hence, let's rename this to make it less misleading.
* sleep: log about the correct errorsLennart Poettering2018-10-241-2/+2
|
* sleep: don't make up errors, propagate the right onesLennart Poettering2018-10-241-3/+6
|
* sleep: let's use write_string_file() instead of write_string_stream() if we canLennart Poettering2018-10-241-7/+1
| | | | Let's shorten things.
* shared/sleep-config: add switches to kill specific sleep modesZbigniew Jędrzejewski-Szmek2018-10-081-6/+9
| | | | | | | | | | | | /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.
* exec-util: in execute_directories, support initial exec environmentDimitri John Ledkov2018-09-241-2/+2
|
* tree-wide: add clickable man page link to all --help textsLennart Poettering2018-08-201-11/+23
| | | | | | | | | | This is a bit like the info link in most of GNU's --help texts, but we don't do info but man pages, and we make them properly clickable on terminal supporting that, because awesome. I think it's generally advisable to link up our (brief) --help texts and our (more comprehensive) man pages a bit, so this should be an easy and straight-forward way to do it.
* sleep: tiny coding style updatesLennart Poettering2018-07-171-26/+28
| | | | No change in behaviour
* Drop my copyright headersZbigniew Jędrzejewski-Szmek2018-06-141-1/+0
| | | | | | | 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'
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-3/+3
| | | | | | 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.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-1/+0
| | | | | | | | | | | 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.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | 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.