From: Mike Yuan Date: Wed, 20 Sep 2023 13:19:07 +0000 (+0800) Subject: sleep-util: move check_wakeup_type to sleep/sleep X-Git-Tag: v255-rc1~407^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1482feda0193bb6e7c3cc4bc86285d655835f5c1;p=thirdparty%2Fsystemd.git sleep-util: move check_wakeup_type to sleep/sleep --- diff --git a/src/shared/sleep-util.c b/src/shared/sleep-util.c index d7277399fba..57c4c45c367 100644 --- a/src/shared/sleep-util.c +++ b/src/shared/sleep-util.c @@ -471,40 +471,6 @@ int battery_trip_point_alarm_exists(void) { return true; } -/* Return true if wakeup type is APM timer */ -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; -} - int can_sleep_state(char **requested_types) { _cleanup_free_ char *text = NULL; int r; diff --git a/src/shared/sleep-util.h b/src/shared/sleep-util.h index 6480ca86373..038587bde72 100644 --- a/src/shared/sleep-util.h +++ b/src/shared/sleep-util.h @@ -77,7 +77,6 @@ int estimate_battery_discharge_rate_per_hour( Hashmap *current_capacity, usec_t before_timestamp, usec_t after_timestamp); -int check_wakeup_type(void); int battery_trip_point_alarm_exists(void); const char* sleep_operation_to_string(SleepOperation s) _const_; diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 76b69f817ae..f837e4d21a0 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;