systemd-252-5

Resolves: #1952378,#2151612,#2167468,#2170500
This commit is contained in:
Jan Macku 2023-02-17 09:20:01 +01:00
parent 2d7302fd0b
commit 942940330e
13 changed files with 854 additions and 1 deletions

View File

@ -0,0 +1,27 @@
From 0858da8425a71641fe32222bc91c060856dcb217 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 9 Feb 2023 05:55:42 +0900
Subject: [PATCH] nss-myhostname: fix inverted condition in
Fixes a bug introduced by db50d326a46beca3cc24b6354b6e1b3591902d45.
(cherry picked from commit a3b993ca3fb6fc0b837745c1ae82aca684951842)
Resolves: #2167468
---
src/nss-myhostname/nss-myhostname.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 120e76be45..93db9d16e7 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -460,7 +460,7 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
} else {
assert(af == AF_INET6);
- if (socket_ipv6_is_enabled())
+ if (!socket_ipv6_is_enabled())
goto not_found;
if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) {

View File

@ -0,0 +1,34 @@
From 86bbeff62982404dc76e79d3dad8a8c59308d017 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 9 Feb 2023 06:07:13 +0900
Subject: [PATCH] nss-myhostname: do not return empty result with
NSS_STATUS_SUCCESS
Fixes a bug introduced by db50d326a46beca3cc24b6354b6e1b3591902d45.
Fixes RHBZ#2167468 (https://bugzilla.redhat.com/show_bug.cgi?id=2167468).
(cherry picked from commit 1c3762937e9184c9abbc8d5541b4228841ccc24f)
Resolves: #2167468
---
src/nss-myhostname/nss-myhostname.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 93db9d16e7..d574e98a71 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -345,9 +345,10 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_UNAVAIL;
}
+ if (af == AF_INET6 && !socket_ipv6_is_enabled())
+ goto not_found;
+
if (is_localhost(name)) {
- if (af == AF_INET6 && !socket_ipv6_is_enabled())
- goto not_found;
canonical = "localhost";
local_address_ipv4 = htobe32(INADDR_LOOPBACK);

View File

@ -0,0 +1,64 @@
From 51a4778726edd7dfad18e7354bda1d77730c8dd8 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 13 Nov 2022 23:59:49 +0900
Subject: [PATCH] sleep: rename hibernate_delay_sec -> _usec
(cherry picked from commit 3d23df005e06b3616049686be82deff55788d3c4)
Related: #2151612
---
src/shared/sleep-config.c | 6 +++---
src/shared/sleep-config.h | 2 +-
src/sleep/sleep.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index efc066c4f2..359d293fd0 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -82,7 +82,7 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
{ "Sleep", "HybridSleepMode", config_parse_strv, 0, sc->modes + SLEEP_HYBRID_SLEEP },
{ "Sleep", "HybridSleepState", config_parse_strv, 0, sc->states + SLEEP_HYBRID_SLEEP },
- { "Sleep", "HibernateDelaySec", config_parse_sec, 0, &sc->hibernate_delay_sec },
+ { "Sleep", "HibernateDelaySec", config_parse_sec, 0, &sc->hibernate_delay_usec },
{}
};
@@ -113,8 +113,8 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
sc->modes[SLEEP_HYBRID_SLEEP] = strv_new("suspend", "platform", "shutdown");
if (!sc->states[SLEEP_HYBRID_SLEEP])
sc->states[SLEEP_HYBRID_SLEEP] = strv_new("disk");
- if (sc->hibernate_delay_sec == 0)
- sc->hibernate_delay_sec = 2 * USEC_PER_HOUR;
+ if (sc->hibernate_delay_usec == 0)
+ sc->hibernate_delay_usec = 2 * USEC_PER_HOUR;
/* ensure values set for all required fields */
if (!sc->states[SLEEP_SUSPEND] || !sc->modes[SLEEP_HIBERNATE]
diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h
index 6645c3e596..226fab4b9f 100644
--- a/src/shared/sleep-config.h
+++ b/src/shared/sleep-config.h
@@ -19,7 +19,7 @@ typedef struct SleepConfig {
bool allow[_SLEEP_OPERATION_MAX];
char **modes[_SLEEP_OPERATION_MAX];
char **states[_SLEEP_OPERATION_MAX];
- usec_t hibernate_delay_sec;
+ usec_t hibernate_delay_usec;
} SleepConfig;
SleepConfig* free_sleep_config(SleepConfig *sc);
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 3461d3e45f..7679f2e3be 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -275,7 +275,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
while (battery_is_low() == 0) {
_cleanup_close_ int tfd = -1;
struct itimerspec ts = {};
- usec_t suspend_interval = sleep_config->hibernate_delay_sec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;
+ usec_t suspend_interval = sleep_config->hibernate_delay_usec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;
bool woken_by_timer;
tfd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK|TFD_CLOEXEC);

View File

@ -0,0 +1,80 @@
From d46e3dedada3d57db518ae3f9f857fd26050a4dd Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 08:31:09 +0900
Subject: [PATCH] sleep: fetch_batteries_capacity_by_name() does not return
-ENOENT
(cherry picked from commit d812e104c7c62648747d3ffe37db33dde319d15c)
Related: #2151612
---
src/sleep/sleep.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 7679f2e3be..11a2ba507d 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -275,21 +275,16 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
while (battery_is_low() == 0) {
_cleanup_close_ int tfd = -1;
struct itimerspec ts = {};
- usec_t suspend_interval = sleep_config->hibernate_delay_usec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;
+ usec_t suspend_interval = sleep_config->hibernate_delay_usec, total_suspend_interval;
bool woken_by_timer;
tfd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK|TFD_CLOEXEC);
if (tfd < 0)
return log_error_errno(errno, "Error creating timerfd: %m");
- /* Store current battery capacity and current time before suspension */
+ /* Store current battery capacity before suspension */
r = fetch_batteries_capacity_by_name(&last_capacity);
- if (r >= 0)
- before_timestamp = now(CLOCK_BOOTTIME);
- else if (r == -ENOENT)
- /* In case of no battery, system suspend interval will be set to HibernateDelaySec=. */
- log_debug_errno(r, "Suspend Interval value set to %s: %m", FORMAT_TIMESPAN(suspend_interval, USEC_PER_SEC));
- else
+ if (r < 0)
return log_error_errno(r, "Error fetching battery capacity percentage: %m");
r = get_total_suspend_interval(last_capacity, &total_suspend_interval);
@@ -298,6 +293,8 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
else
suspend_interval = total_suspend_interval;
+ usec_t before_timestamp = now(CLOCK_BOOTTIME);
+
log_debug("Set timerfd wake alarm for %s", FORMAT_TIMESPAN(suspend_interval, USEC_PER_SEC));
/* Wake alarm for system with or without battery to hibernate or estimate discharge rate whichever is applicable */
timespec_store(&ts.it_value, suspend_interval);
@@ -316,18 +313,22 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
woken_by_timer = FLAGS_SET(r, POLLIN);
r = fetch_batteries_capacity_by_name(&current_capacity);
- if (r < 0) {
+ if (r < 0 || hashmap_isempty(current_capacity)) {
/* In case of no battery or error while getting charge level, no need to measure
- * discharge rate. Instead system should wakeup if it is manual wakeup or
- * hibernate if this is a timer wakeup. */
- log_debug_errno(r, "Battery capacity percentage unavailable, cannot estimate discharge rate: %m");
+ * discharge rate. Instead the system should wake up if it is manual wakeup or
+ * hibernate if this is a timer wakeup. */
+ if (r < 0)
+ log_debug_errno(r, "Battery capacity percentage unavailable, cannot estimate discharge rate: %m");
+ else
+ log_debug("No battery found.");
if (!woken_by_timer)
return 0;
break;
}
- after_timestamp = now(CLOCK_BOOTTIME);
- log_debug("Attempting to estimate battery discharge rate after wakeup from %s sleep", FORMAT_TIMESPAN(after_timestamp - before_timestamp, USEC_PER_HOUR));
+ usec_t after_timestamp = now(CLOCK_BOOTTIME);
+ log_debug("Attempting to estimate battery discharge rate after wakeup from %s sleep",
+ FORMAT_TIMESPAN(after_timestamp - before_timestamp, USEC_PER_HOUR));
if (after_timestamp != before_timestamp) {
r = estimate_battery_discharge_rate_per_hour(last_capacity, current_capacity, before_timestamp, after_timestamp);

View File

@ -0,0 +1,42 @@
From 176ceed28620a9358c5528a039b74211187bcf13 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 00:09:34 +0900
Subject: [PATCH] sleep: drop unnecessary temporal vaiable and initialization
(cherry picked from commit 2ed56afeb3c26596dbe44858559c92307778ff82)
Related: #2151612
---
src/sleep/sleep.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 11a2ba507d..039b123dcc 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -275,7 +275,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
while (battery_is_low() == 0) {
_cleanup_close_ int tfd = -1;
struct itimerspec ts = {};
- usec_t suspend_interval = sleep_config->hibernate_delay_usec, total_suspend_interval;
+ usec_t suspend_interval;
bool woken_by_timer;
tfd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK|TFD_CLOEXEC);
@@ -287,11 +287,12 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
if (r < 0)
return log_error_errno(r, "Error fetching battery capacity percentage: %m");
- r = get_total_suspend_interval(last_capacity, &total_suspend_interval);
- if (r < 0)
+ r = get_total_suspend_interval(last_capacity, &suspend_interval);
+ if (r < 0) {
log_debug_errno(r, "Failed to estimate suspend interval using previous discharge rate, ignoring: %m");
- else
- suspend_interval = total_suspend_interval;
+ /* In case of no battery or any errors, system suspend interval will be set to HibernateDelaySec=. */
+ suspend_interval = sleep_config->hibernate_delay_usec;
+ }
usec_t before_timestamp = now(CLOCK_BOOTTIME);

View File

@ -0,0 +1,270 @@
From db8a187c67e4829e39fe28e25003816b64db80db Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 02:08:05 +0900
Subject: [PATCH] sleep: introduce SuspendEstimationSec=
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.
(cherry picked from commit 4f58b656d92b09a953b7cffcfd1ee6d5136a57ed)
Resolves: #2151612
---
man/systemd-sleep.conf.xml | 58 ++++++++++++++++++++------------------
src/shared/sleep-config.c | 11 ++++++--
src/shared/sleep-config.h | 3 ++
src/sleep/sleep.c | 48 ++++++++++++++++++++++---------
src/sleep/sleep.conf | 3 +-
5 files changed, 77 insertions(+), 46 deletions(-)
diff --git a/man/systemd-sleep.conf.xml b/man/systemd-sleep.conf.xml
index be04f2cdf1..79ebef1fef 100644
--- a/man/systemd-sleep.conf.xml
+++ b/man/systemd-sleep.conf.xml
@@ -77,29 +77,16 @@
<varlistentry>
<term>suspend-then-hibernate</term>
- <listitem><para>A low power state where initially user.slice unit is freezed.
- If the hardware supports low-battery alarms (ACPI _BTP), then the system is
- first suspended (the state is stored in RAM) and then hibernates if the system
- is woken up by the hardware via ACPI low-battery signal. Unit user.slice is
- thawed when system returns from hibernation. If the hardware does not support
- low-battery alarms (ACPI _BTP), then the system is suspended based on battery's
- current percentage capacity. If the current battery capacity is higher than 5%, the
- system suspends for interval calculated using battery discharge rate per hour or
- <command>HibernateDelaySec=</command>
- if former is not available.
- Battery discharge rate per hour is stored in a file which is created after
- initial suspend-resume cycle. The value is calculated using battery decreasing
- charge level over a timespan for which system was suspended. For each battery
- connected to the system, there is a unique entry. After RTC alarm wakeup from
- suspend, battery discharge rate per hour is again estimated. If the current battery
- charge level is equal to or less than 5%, the system will be hibernated (the state
- is then stored on disk) else the system goes back to suspend for the interval
- calculated using battery discharge rate per hour.
- In case of manual wakeup, if the battery was discharged while the system was
- suspended, the battery discharge rate is estimated and stored on the filesystem.
- In case the system is woken up by the hardware via the ACPI low-battery signal,
- then it hibernates.
- </para></listitem>
+ <listitem>
+ <para>A low power state where the system is initially suspended (the state is stored in
+ RAM). If the system supports low-battery alarms (ACPI _BTP), then the system will be woken up by
+ the ACPI low-battery signal and hibernated (the state is then stored on disk). Also, if not
+ interrupted within the timespan specified by <varname>HibernateDelaySec=</varname> or the estimated
+ timespan until the system battery charge level goes down to 5%, then the system will be woken up by the
+ RTC alarm and hibernated. The estimated timespan is calculated from the change of the battery
+ capacity level after the time specified by <varname>SuspendEstimationSec=</varname> or when
+ the system is woken up from the suspend.</para>
+ </listitem>
</varlistentry>
</variablelist>
@@ -189,13 +176,28 @@
uses the value of <varname>SuspendState=</varname> when suspending and the value of <varname>HibernateState=</varname> when hibernating.
</para></listitem>
</varlistentry>
+
<varlistentry>
<term><varname>HibernateDelaySec=</varname></term>
- <listitem><para>The amount of time the system spends in suspend mode
- before the RTC alarm wakes the system, before the battery discharge rate
- can be estimated and used instead to calculate the suspension interval.
- <citerefentry><refentrytitle>systemd-suspend-then-hibernate.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. Defaults
- to 2h.</para></listitem>
+
+ <listitem>
+ <para>The amount of time the system spends in suspend mode before the system is
+ automatically put into hibernate mode. Only used by
+ <citerefentry><refentrytitle>systemd-suspend-then-hibernate.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
+ If the system has a battery, then defaults to the estimated timespan until the system battery charge level goes down to 5%.
+ If the system has no battery, then defaults to 2h.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>SuspendEstimationSec=</varname></term>
+
+ <listitem>
+ <para>The RTC alarm will wake the system after the specified timespan to measure the system battery
+ capacity level and estimate battery discharging rate, which is used for estimating timespan until the system battery charge
+ level goes down to 5%. Only used by
+ <citerefentry><refentrytitle>systemd-suspend-then-hibernate.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
+ Defaults to 2h.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 359d293fd0..74653effa2 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -65,10 +65,14 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
int allow_suspend = -1, allow_hibernate = -1,
allow_s2h = -1, allow_hybrid_sleep = -1;
- sc = new0(SleepConfig, 1);
+ sc = new(SleepConfig, 1);
if (!sc)
return log_oom();
+ *sc = (SleepConfig) {
+ .hibernate_delay_usec = USEC_INFINITY,
+ };
+
const ConfigTableItem items[] = {
{ "Sleep", "AllowSuspend", config_parse_tristate, 0, &allow_suspend },
{ "Sleep", "AllowHibernation", config_parse_tristate, 0, &allow_hibernate },
@@ -83,6 +87,7 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
{ "Sleep", "HybridSleepState", config_parse_strv, 0, sc->states + SLEEP_HYBRID_SLEEP },
{ "Sleep", "HibernateDelaySec", config_parse_sec, 0, &sc->hibernate_delay_usec },
+ { "Sleep", "SuspendEstimationSec", config_parse_sec, 0, &sc->suspend_estimation_usec },
{}
};
@@ -113,8 +118,8 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
sc->modes[SLEEP_HYBRID_SLEEP] = strv_new("suspend", "platform", "shutdown");
if (!sc->states[SLEEP_HYBRID_SLEEP])
sc->states[SLEEP_HYBRID_SLEEP] = strv_new("disk");
- if (sc->hibernate_delay_usec == 0)
- sc->hibernate_delay_usec = 2 * USEC_PER_HOUR;
+ if (sc->suspend_estimation_usec == 0)
+ sc->suspend_estimation_usec = DEFAULT_SUSPEND_ESTIMATION_USEC;
/* ensure values set for all required fields */
if (!sc->states[SLEEP_SUSPEND] || !sc->modes[SLEEP_HIBERNATE]
diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h
index 226fab4b9f..480e90c95b 100644
--- a/src/shared/sleep-config.h
+++ b/src/shared/sleep-config.h
@@ -6,6 +6,8 @@
#include "hashmap.h"
#include "time-util.h"
+#define DEFAULT_SUSPEND_ESTIMATION_USEC (1 * USEC_PER_HOUR)
+
typedef enum SleepOperation {
SLEEP_SUSPEND,
SLEEP_HIBERNATE,
@@ -20,6 +22,7 @@ typedef struct SleepConfig {
char **modes[_SLEEP_OPERATION_MAX];
char **states[_SLEEP_OPERATION_MAX];
usec_t hibernate_delay_usec;
+ usec_t suspend_estimation_usec;
} SleepConfig;
SleepConfig* free_sleep_config(SleepConfig *sc);
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 039b123dcc..0bbea9e856 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -268,10 +268,13 @@ static int execute(
static int custom_timer_suspend(const SleepConfig *sleep_config) {
_cleanup_hashmap_free_ Hashmap *last_capacity = NULL, *current_capacity = NULL;
+ usec_t hibernate_timestamp;
int r;
assert(sleep_config);
+ hibernate_timestamp = usec_add(now(CLOCK_BOOTTIME), sleep_config->hibernate_delay_usec);
+
while (battery_is_low() == 0) {
_cleanup_close_ int tfd = -1;
struct itimerspec ts = {};
@@ -287,14 +290,25 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
if (r < 0)
return log_error_errno(r, "Error fetching battery capacity percentage: %m");
- r = get_total_suspend_interval(last_capacity, &suspend_interval);
- if (r < 0) {
- log_debug_errno(r, "Failed to estimate suspend interval using previous discharge rate, ignoring: %m");
- /* In case of no battery or any errors, system suspend interval will be set to HibernateDelaySec=. */
- suspend_interval = sleep_config->hibernate_delay_usec;
+ if (hashmap_isempty(last_capacity))
+ /* In case of no battery, system suspend interval will be set to HibernateDelaySec= or 2 hours. */
+ suspend_interval = timestamp_is_set(hibernate_timestamp) ? sleep_config->hibernate_delay_usec : DEFAULT_SUSPEND_ESTIMATION_USEC;
+ else {
+ r = get_total_suspend_interval(last_capacity, &suspend_interval);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to estimate suspend interval using previous discharge rate, ignoring: %m");
+ /* In case of any errors, especially when we do not know the battery
+ * discharging rate, system suspend interval will be set to
+ * SuspendEstimationSec=. */
+ suspend_interval = sleep_config->suspend_estimation_usec;
+ }
}
+ /* Do not suspend more than HibernateDelaySec= */
usec_t before_timestamp = now(CLOCK_BOOTTIME);
+ suspend_interval = MIN(suspend_interval, usec_sub_unsigned(hibernate_timestamp, before_timestamp));
+ if (suspend_interval <= 0)
+ break; /* system should hibernate */
log_debug("Set timerfd wake alarm for %s", FORMAT_TIMESPAN(suspend_interval, USEC_PER_SEC));
/* Wake alarm for system with or without battery to hibernate or estimate discharge rate whichever is applicable */
@@ -377,7 +391,7 @@ static int freeze_thaw_user_slice(const char **method) {
static int execute_s2h(const SleepConfig *sleep_config) {
_unused_ _cleanup_(freeze_thaw_user_slice) const char *auto_method_thaw = NULL;
- int r, k;
+ int r;
assert(sleep_config);
@@ -387,15 +401,21 @@ static int execute_s2h(const SleepConfig *sleep_config) {
else
auto_method_thaw = "ThawUnit"; /* from now on we want automatic thawing */;
- r = check_wakeup_type();
- if (r < 0)
- log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
-
- k = battery_trip_point_alarm_exists();
- if (k < 0)
- log_debug_errno(k, "Failed to check whether acpi_btp support is enabled or not, ignoring: %m");
+ /* Only check if we have automated battery alarms if HibernateDelaySec= is not set, as in that case
+ * we'll busy poll for the configured interval instead */
+ if (!timestamp_is_set(sleep_config->hibernate_delay_usec)) {
+ r = check_wakeup_type();
+ if (r < 0)
+ log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
+ else {
+ r = battery_trip_point_alarm_exists();
+ if (r < 0)
+ log_debug_errno(r, "Failed to check whether acpi_btp support is enabled or not, ignoring: %m");
+ }
+ } else
+ r = 0; /* Force fallback path */
- if (r >= 0 && k > 0) {
+ if (r > 0) { /* If we have both wakeup alarms and battery trip point support, use them */
log_debug("Attempting to suspend...");
r = execute(sleep_config, SLEEP_SUSPEND, NULL);
if (r < 0)
diff --git a/src/sleep/sleep.conf b/src/sleep/sleep.conf
index a3d31140d8..4c8e8b9680 100644
--- a/src/sleep/sleep.conf
+++ b/src/sleep/sleep.conf
@@ -23,4 +23,5 @@
#HibernateState=disk
#HybridSleepMode=suspend platform shutdown
#HybridSleepState=disk
-#HibernateDelaySec=120min
+#HibernateDelaySec=
+#SuspendEstimationSec=60min

View File

@ -0,0 +1,28 @@
From 583e9f1af5642643f11bc1cab26989a4f1dff776 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 02:44:13 +0900
Subject: [PATCH] sleep: coding style fixlets
(cherry picked from commit 3c3f46013ed53aba1aad5b51844434713fa5a0e9)
Related: #2151612
---
src/sleep/sleep.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 0bbea9e856..bfd8ef3670 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -430,9 +430,9 @@ static int execute_s2h(const SleepConfig *sleep_config) {
return 0;
} else {
r = custom_timer_suspend(sleep_config);
- if(r < 0)
+ if (r < 0)
return log_debug_errno(r, "Suspend cycle with manual battery discharge rate estimation failed: %m");
- if(r == 0)
+ if (r == 0)
/* manual wakeup */
return 0;
}

View File

@ -0,0 +1,66 @@
From d46e822fad4b5d43d5e53e21c7de3168bb547ded Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 02:46:53 +0900
Subject: [PATCH] sleep: simplify code a bit
- use device_get_sysattr_int(),
- drop redundant log message.
(cherry picked from commit 3d9ca76f368b7b198be3471dd28ed32b35114ace)
Related: #2151612
---
src/shared/sleep-config.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 74653effa2..25c3bd2925 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -22,6 +22,7 @@
#include "btrfs-util.h"
#include "conf-parser.h"
#include "def.h"
+#include "device-private.h"
#include "device-util.h"
#include "devnum-util.h"
#include "env-util.h"
@@ -170,18 +171,13 @@ static int get_capacity_by_name(Hashmap *capacities_by_name, const char *name) {
/* Battery percentage capacity fetched from capacity file and if in range 0-100 then returned */
static int read_battery_capacity_percentage(sd_device *dev) {
- const char *power_supply_capacity;
int battery_capacity, r;
assert(dev);
- r = sd_device_get_property_value(dev, "POWER_SUPPLY_CAPACITY", &power_supply_capacity);
+ r = device_get_sysattr_int(dev, "capacity", &battery_capacity);
if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to read battery capacity: %m");
-
- r = safe_atoi(power_supply_capacity, &battery_capacity);
- if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to parse battery capacity: %m");
+ return log_device_debug_errno(dev, r, "Failed to read/parse POWER_SUPPLY_CAPACITY: %m");
if (battery_capacity < 0 || battery_capacity > 100)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ERANGE), "Invalid battery capacity");
@@ -203,15 +199,9 @@ int battery_is_low(void) {
if (r < 0)
return log_debug_errno(r, "Failed to initialize battery enumerator: %m");
- FOREACH_DEVICE(e, dev) {
- r = read_battery_capacity_percentage(dev);
- if (r < 0) {
- log_device_debug_errno(dev, r, "Failed to get battery capacity, ignoring: %m");
- continue;
- }
- if (r > BATTERY_LOW_CAPACITY_LEVEL)
+ FOREACH_DEVICE(e, dev)
+ if (read_battery_capacity_percentage(dev) > BATTERY_LOW_CAPACITY_LEVEL)
return false;
- }
return true;
}

View File

@ -0,0 +1,33 @@
From 57eb0c1c4903901717b4a81dd674aabb2c0ab2b3 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 02:52:55 +0900
Subject: [PATCH] sleep: fix indentation
(cherry picked from commit 3332cfe1764e3c15d9af2ef68097d0f698fddb3d)
Related: #2151612
---
src/shared/sleep-config.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 25c3bd2925..4c08e97c8a 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -388,11 +388,11 @@ static int put_battery_discharge_rate(int estimated_battery_discharge_rate, uint
estimated_battery_discharge_rate);
r = write_string_filef(
- DISCHARGE_RATE_FILEPATH,
- WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_MKDIR_0755 | (trunc ? WRITE_STRING_FILE_TRUNCATE : 0),
- "%"PRIu64" %d",
- system_hash_id,
- estimated_battery_discharge_rate);
+ DISCHARGE_RATE_FILEPATH,
+ WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_MKDIR_0755 | (trunc ? WRITE_STRING_FILE_TRUNCATE : 0),
+ "%"PRIu64" %d",
+ system_hash_id,
+ estimated_battery_discharge_rate);
if (r < 0)
return log_debug_errno(r, "Failed to update %s: %m", DISCHARGE_RATE_FILEPATH);

View File

@ -0,0 +1,50 @@
From 49d626105a5739bf7fa725f578d02b8873c282c7 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 14 Nov 2022 02:54:50 +0900
Subject: [PATCH] sleep: enumerate only existing and non-device batteries
The enumerator is now mostly consistent with on_ac_power() in
udev-util.c.
(cherry picked from commit fe8e0f8e7989fe5cead5ad0e225dc0888ff10140)
Related: #2151612
---
src/shared/sleep-config.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 4c08e97c8a..2d55e7c860 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -143,16 +143,27 @@ static int battery_enumerator_new(sd_device_enumerator **ret) {
if (r < 0)
return r;
- r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match= */ true);
+ r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match = */ true);
if (r < 0)
return r;
- r = sd_device_enumerator_add_match_property(e, "POWER_SUPPLY_TYPE", "Battery");
+ r = sd_device_enumerator_allow_uninitialized(e);
if (r < 0)
return r;
- *ret = TAKE_PTR(e);
+ r = sd_device_enumerator_add_match_sysattr(e, "type", "Battery", /* match = */ true);
+ if (r < 0)
+ return r;
+
+ r = sd_device_enumerator_add_match_sysattr(e, "present", "1", /* match = */ true);
+ if (r < 0)
+ return r;
+ r = sd_device_enumerator_add_match_sysattr(e, "scope", "Device", /* match = */ false);
+ if (r < 0)
+ return r;
+
+ *ret = TAKE_PTR(e);
return 0;
}

View File

@ -0,0 +1,78 @@
From 9be28013e62ae471151fdc1f181e21cbd1e72dbd Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Fri, 10 Feb 2023 13:38:08 +0100
Subject: [PATCH] core: when isolating to a unit, also keep units running that
are triggered by units we keep running
Inspired by: #26364
(this might even "fix" #26364, but without debug logs it's hard to make
such claims)
Fixes: #23055
(cherry picked from commit 32d6707dd1692d41e12f5469dfdcbc10f14d6619)
Resolves: #1952378
---
src/core/transaction.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/core/transaction.c b/src/core/transaction.c
index bafbb80b47..8ec853d58d 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -1092,6 +1092,20 @@ fail:
return r;
}
+static bool shall_stop_on_isolate(Transaction *tr, Unit *u) {
+ assert(tr);
+ assert(u);
+
+ if (u->ignore_on_isolate)
+ return false;
+
+ /* Is there already something listed for this? */
+ if (hashmap_get(tr->jobs, u))
+ return false;
+
+ return true;
+}
+
int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
Unit *u;
char *k;
@@ -1101,20 +1115,27 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
assert(m);
HASHMAP_FOREACH_KEY(u, k, m->units) {
+ Unit *o;
- /* ignore aliases */
+ /* Ignore aliases */
if (u->id != k)
continue;
- if (u->ignore_on_isolate)
+ /* No need to stop inactive units */
+ if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
continue;
- /* No need to stop inactive jobs */
- if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
+ if (!shall_stop_on_isolate(tr, u))
continue;
- /* Is there already something listed for this? */
- if (hashmap_get(tr->jobs, u))
+ /* Keep units that are triggered by units we want to keep around. */
+ bool keep = false;
+ UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY)
+ if (!shall_stop_on_isolate(tr, o)) {
+ keep = true;
+ break;
+ }
+ if (keep)
continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL);

View File

@ -0,0 +1,55 @@
From edbd954a140b097e3fc4c9246bda88a43692122b Mon Sep 17 00:00:00 2001
From: Jan Macku <jamacku@redhat.com>
Date: Thu, 16 Feb 2023 16:08:57 +0100
Subject: [PATCH] udev/net_id: introduce naming scheme for RHEL-9.2
RHEL-only
Resolves: #2170500
---
man/systemd.net-naming-scheme.xml | 6 ++++++
src/shared/netif-naming-scheme.c | 1 +
src/shared/netif-naming-scheme.h | 1 +
3 files changed, 8 insertions(+)
diff --git a/man/systemd.net-naming-scheme.xml b/man/systemd.net-naming-scheme.xml
index ca8ba7010e..0886369c9b 100644
--- a/man/systemd.net-naming-scheme.xml
+++ b/man/systemd.net-naming-scheme.xml
@@ -466,6 +466,12 @@
<listitem><para>Same as naming scheme <constant>rhel-9.0</constant>.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><constant>rhel-9.2</constant></term>
+
+ <listitem><para>Same as naming scheme <constant>rhel-9.0</constant>.</para></listitem>
+ </varlistentry>
+
</variablelist>
<para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this
diff --git a/src/shared/netif-naming-scheme.c b/src/shared/netif-naming-scheme.c
index a20b990f2e..d846c794a8 100644
--- a/src/shared/netif-naming-scheme.c
+++ b/src/shared/netif-naming-scheme.c
@@ -27,6 +27,7 @@ static const NamingScheme naming_schemes[] = {
{ "v252", NAMING_V252 },
{ "rhel-9.0", NAMING_RHEL_9_0 },
{ "rhel-9.1", NAMING_RHEL_9_1 },
+ { "rhel-9.2", NAMING_RHEL_9_2 },
/* … add more schemes here, as the logic to name devices is updated … */
EXTRA_NET_NAMING_MAP
diff --git a/src/shared/netif-naming-scheme.h b/src/shared/netif-naming-scheme.h
index d70c19ade3..3e35c5e2fa 100644
--- a/src/shared/netif-naming-scheme.h
+++ b/src/shared/netif-naming-scheme.h
@@ -53,6 +53,7 @@ typedef enum NamingSchemeFlags {
NAMING_V252 = NAMING_V251 | NAMING_DEVICETREE_ALIASES,
NAMING_RHEL_9_0 = NAMING_V250 | NAMING_BRIDGE_MULTIFUNCTION_SLOT,
NAMING_RHEL_9_1 = NAMING_RHEL_9_0,
+ NAMING_RHEL_9_2 = NAMING_RHEL_9_0,
EXTRA_NET_NAMING_SCHEMES

View File

@ -21,7 +21,7 @@
Name: systemd Name: systemd
Url: https://www.freedesktop.org/wiki/Software/systemd Url: https://www.freedesktop.org/wiki/Software/systemd
Version: 252 Version: 252
Release: 4%{?dist} Release: 5%{?dist}
# For a breakdown of the licensing, see README # For a breakdown of the licensing, see README
License: LGPLv2+ and MIT and GPLv2+ License: LGPLv2+ and MIT and GPLv2+
Summary: System and Service Manager Summary: System and Service Manager
@ -285,6 +285,18 @@ Patch0204: 0204-resolve-introduce-link_get_llmnr_support-and-link_ge.patch
Patch0205: 0205-resolve-provide-effective-supporting-levels-of-mDNS-.patch Patch0205: 0205-resolve-provide-effective-supporting-levels-of-mDNS-.patch
Patch0206: 0206-resolvectl-warn-if-the-global-mDNS-or-LLMNR-support-.patch Patch0206: 0206-resolvectl-warn-if-the-global-mDNS-or-LLMNR-support-.patch
Patch0207: 0207-resolve-enable-per-link-mDNS-setting-by-default.patch Patch0207: 0207-resolve-enable-per-link-mDNS-setting-by-default.patch
Patch0208: 0208-nss-myhostname-fix-inverted-condition-in.patch
Patch0209: 0209-nss-myhostname-do-not-return-empty-result-with-NSS_S.patch
Patch0210: 0210-sleep-rename-hibernate_delay_sec-_usec.patch
Patch0211: 0211-sleep-fetch_batteries_capacity_by_name-does-not-retu.patch
Patch0212: 0212-sleep-drop-unnecessary-temporal-vaiable-and-initiali.patch
Patch0213: 0213-sleep-introduce-SuspendEstimationSec.patch
Patch0214: 0214-sleep-coding-style-fixlets.patch
Patch0215: 0215-sleep-simplify-code-a-bit.patch
Patch0216: 0216-sleep-fix-indentation.patch
Patch0217: 0217-sleep-enumerate-only-existing-and-non-device-batteri.patch
Patch0218: 0218-core-when-isolating-to-a-unit-also-keep-units-runnin.patch
Patch0219: 0219-udev-net_id-introduce-naming-scheme-for-RHEL-9.2.patch
# Downstream-only patches (90009999) # Downstream-only patches (90009999)
@ -1076,6 +1088,20 @@ getent passwd systemd-oom &>/dev/null || useradd -r -l -g systemd-oom -d / -s /s
%files standalone-sysusers -f .file-list-standalone-sysusers %files standalone-sysusers -f .file-list-standalone-sysusers
%changelog %changelog
* Fri Feb 17 2023 systemd maintenance team <systemd-maint@redhat.com> - 252-5
- nss-myhostname: fix inverted condition in (#2167468)
- nss-myhostname: do not return empty result with NSS_STATUS_SUCCESS (#2167468)
- sleep: rename hibernate_delay_sec -> _usec (#2151612)
- sleep: fetch_batteries_capacity_by_name() does not return -ENOENT (#2151612)
- sleep: drop unnecessary temporal vaiable and initialization (#2151612)
- sleep: introduce SuspendEstimationSec= (#2151612)
- sleep: coding style fixlets (#2151612)
- sleep: simplify code a bit (#2151612)
- sleep: fix indentation (#2151612)
- sleep: enumerate only existing and non-device batteries (#2151612)
- core: when isolating to a unit, also keep units running that are triggered by units we keep running (#1952378)
- udev/net_id: introduce naming scheme for RHEL-9.2 (#2170500)
* Mon Feb 06 2023 systemd maintenance team <systemd-maint@redhat.com> - 252-4 * Mon Feb 06 2023 systemd maintenance team <systemd-maint@redhat.com> - 252-4
- udev: make get_virtfn_info() provide physical PCI device (#2159448) - udev: make get_virtfn_info() provide physical PCI device (#2159448)
- test: make helper_check_device_units() log unit name (#2138081) - test: make helper_check_device_units() log unit name (#2138081)