mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-11 04:58:19 +03:00
sd-event: always initialize sd_event.perturb
If the boot ID cannot be obtained, let's first fallback to the machine ID, and if still cannot, then let's use 0. Otherwise, no timer event source cannot be triggered. Fixes #26549.
This commit is contained in:
parent
a954b2492e
commit
6d2326e036
@ -1258,22 +1258,21 @@ _public_ int sd_event_add_io(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void initialize_perturb(sd_event *e) {
|
static void initialize_perturb(sd_event *e) {
|
||||||
sd_id128_t bootid = {};
|
sd_id128_t id = {};
|
||||||
|
|
||||||
/* When we sleep for longer, we try to realign the wakeup to
|
/* When we sleep for longer, we try to realign the wakeup to the same time within each
|
||||||
the same time within each minute/second/250ms, so that
|
* minute/second/250ms, so that events all across the system can be coalesced into a single CPU
|
||||||
events all across the system can be coalesced into a single
|
* wakeup. However, let's take some system-specific randomness for this value, so that in a network
|
||||||
CPU wakeup. However, let's take some system-specific
|
* of systems with synced clocks timer events are distributed a bit. Here, we calculate a
|
||||||
randomness for this value, so that in a network of systems
|
* perturbation usec offset from the boot ID (or machine ID if failed, e.g. /proc is not mounted). */
|
||||||
with synced clocks timer events are distributed a
|
|
||||||
bit. Here, we calculate a perturbation usec offset from the
|
|
||||||
boot ID. */
|
|
||||||
|
|
||||||
if (_likely_(e->perturb != USEC_INFINITY))
|
if (_likely_(e->perturb != USEC_INFINITY))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sd_id128_get_boot(&bootid) >= 0)
|
if (sd_id128_get_boot(&id) >= 0 || sd_id128_get_machine(&id) > 0)
|
||||||
e->perturb = (bootid.qwords[0] ^ bootid.qwords[1]) % USEC_PER_MINUTE;
|
e->perturb = (id.qwords[0] ^ id.qwords[1]) % USEC_PER_MINUTE;
|
||||||
|
else
|
||||||
|
e->perturb = 0; /* This is a super early process without /proc and /etc ?? */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int event_setup_timer_fd(
|
static int event_setup_timer_fd(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user