diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-09-20 15:19:07 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-09-27 15:48:39 +0200 |
commit | 1482feda0193bb6e7c3cc4bc86285d655835f5c1 (patch) | |
tree | 5ac17d52244fa43b1a989f725026ce6f9c51dea8 /src/sleep | |
parent | Merge pull request #29296 from yuwata/sd-journal-several-cleanups-for-boot-id (diff) | |
download | systemd-1482feda0193bb6e7c3cc4bc86285d655835f5c1.tar.xz systemd-1482feda0193bb6e7c3cc4bc86285d655835f5c1.zip |
sleep-util: move check_wakeup_type to sleep/sleep
Diffstat (limited to 'src/sleep')
-rw-r--r-- | src/sleep/sleep.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 76b69f817a..f837e4d21a 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -176,6 +176,40 @@ static int write_state(FILE **f, char **states) { return r; } +/* Return true if wakeup type is APM timer */ +static int check_wakeup_type(void) { + static const char dmi_object_path[] = "/sys/firmware/dmi/entries/1-0/raw"; + uint8_t wakeup_type_byte, tablesize; + _cleanup_free_ char *buf = NULL; + size_t bufsize; + int r; + + /* implementation via dmi/entries */ + r = read_full_virtual_file(dmi_object_path, &buf, &bufsize); + if (r < 0) + return log_debug_errno(r, "Unable to read %s: %m", dmi_object_path); + if (bufsize < 25) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Only read %zu bytes from %s (expected 25)", bufsize, dmi_object_path); + + /* index 1 stores the size of table */ + tablesize = (uint8_t) buf[1]; + if (tablesize < 25) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Table size lesser than the index[0x18] where waketype byte is available."); + + wakeup_type_byte = (uint8_t) buf[24]; + /* 0 is Reserved and 8 is AC Power Restored. As per table 12 in + * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.4.0.pdf */ + if (wakeup_type_byte >= 128) + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Expected value in range 0-127"); + + if (wakeup_type_byte == 3) { + log_debug("DMI BIOS System Information indicates wakeup type is APM Timer"); + return true; + } + + return false; +} + static int lock_all_homes(void) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; |