summaryrefslogtreecommitdiffstats
path: root/src/update-utmp/update-utmp.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-26 16:28:32 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-29 00:43:21 +0100
commitf27ae592f70ea5f3f85a178dba3b94140cf808ee (patch)
tree15f2e50fe231ae226ba48cc05ee847e14e4c0159 /src/update-utmp/update-utmp.c
parentman: fix return parameter type of sd_device_get_device_id() (diff)
downloadsystemd-f27ae592f70ea5f3f85a178dba3b94140cf808ee.tar.xz
systemd-f27ae592f70ea5f3f85a178dba3b94140cf808ee.zip
update-utmp: wait slightly longer for the private bus socket being active
Before a339495b1d67f69f49ffffdd96002164a28f1c93, update-utmp typically connects the public DBus socket when disconnected from the private DBus socket, as dbus service should be active even during PID1 is being reexecuted. However, after a339495b1d67f69f49ffffdd96002164a28f1c93, update-utmp tries to connect only the private DBus socket, but reexecution of PID1 may be slow, hence all trials may fail when the reexecution is slow. With this change, now it waits for 100ms to 2000ms, so in total it waits about 37 seconds in average, previously about 4 seconds.
Diffstat (limited to '')
-rw-r--r--src/update-utmp/update-utmp.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c
index 7a8a53f7e8..e40843cf35 100644
--- a/src/update-utmp/update-utmp.c
+++ b/src/update-utmp/update-utmp.c
@@ -65,6 +65,8 @@ static int get_startup_monotonic_time(Context *c, usec_t *ret) {
return 0;
}
+#define MAX_ATTEMPTS 64u
+
static int get_current_runlevel(Context *c) {
static const struct {
const int runlevel;
@@ -84,12 +86,13 @@ static int get_current_runlevel(Context *c) {
for (unsigned n_attempts = 0;;) {
if (n_attempts++ > 0) {
/* systemd might have dropped off momentarily, let's not make this an error,
- * and wait some random time. Let's pick a random time in the range 0ms…250ms,
+ * and wait some random time. Let's pick a random time in the range 100ms…2000ms,
* linearly scaled by the number of failed attempts. */
c->bus = sd_bus_flush_close_unref(c->bus);
- usec_t usec = random_u64_range(UINT64_C(10) * USEC_PER_MSEC +
- UINT64_C(240) * USEC_PER_MSEC * n_attempts/64);
+ usec_t usec =
+ UINT64_C(100) * USEC_PER_MSEC +
+ random_u64_range(UINT64_C(1900) * USEC_PER_MSEC * n_attempts / MAX_ATTEMPTS);
(void) usleep_safe(usec);
r = bus_connect_system_systemd(&c->bus);
@@ -121,7 +124,7 @@ static int get_current_runlevel(Context *c) {
sd_bus_error_has_names(&error,
SD_BUS_ERROR_NO_REPLY,
SD_BUS_ERROR_DISCONNECTED)) &&
- n_attempts < 64) {
+ n_attempts < MAX_ATTEMPTS) {
log_debug_errno(r, "Failed to get state of %s, retrying after a slight delay: %s",
e->special, bus_error_message(&error, r));
break;