1
0
mirror of https://github.com/systemd/systemd synced 2026-03-19 03:24:45 +01:00

Compare commits

..

No commits in common. "f7bef77a16d58d1b0f68ad1c959cd3e72164a767" and "05a2166a068f54d59d68590a81369768c2eb657b" have entirely different histories.

7 changed files with 82 additions and 88 deletions

View File

@ -168,9 +168,10 @@ static int pending_prioq_compare(const void *a, const void *b) {
assert(y->pending); assert(y->pending);
/* Enabled ones first */ /* Enabled ones first */
r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF); if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
if (r != 0) return -1;
return r; if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
return 1;
/* Non rate-limited ones first. */ /* Non rate-limited ones first. */
r = CMP(!!x->ratelimited, !!y->ratelimited); r = CMP(!!x->ratelimited, !!y->ratelimited);
@ -194,9 +195,10 @@ static int prepare_prioq_compare(const void *a, const void *b) {
assert(y->prepare); assert(y->prepare);
/* Enabled ones first */ /* Enabled ones first */
r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF); if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
if (r != 0) return -1;
return r; if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
return 1;
/* Non rate-limited ones first. */ /* Non rate-limited ones first. */
r = CMP(!!x->ratelimited, !!y->ratelimited); r = CMP(!!x->ratelimited, !!y->ratelimited);
@ -263,17 +265,18 @@ static bool event_source_timer_candidate(const sd_event_source *s) {
static int time_prioq_compare(const void *a, const void *b, usec_t (*time_func)(const sd_event_source *s)) { static int time_prioq_compare(const void *a, const void *b, usec_t (*time_func)(const sd_event_source *s)) {
const sd_event_source *x = a, *y = b; const sd_event_source *x = a, *y = b;
int r;
/* Enabled ones first */ /* Enabled ones first */
r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF); if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
if (r != 0) return -1;
return r; if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
return 1;
/* Order "non-pending OR ratelimited" before "pending AND not-ratelimited" */ /* Order "non-pending OR ratelimited" before "pending AND not-ratelimited" */
r = CMP(!event_source_timer_candidate(x), !event_source_timer_candidate(y)); if (event_source_timer_candidate(x) && !event_source_timer_candidate(y))
if (r != 0) return -1;
return r; if (!event_source_timer_candidate(x) && event_source_timer_candidate(y))
return 1;
/* Order by time */ /* Order by time */
return CMP(time_func(x), time_func(y)); return CMP(time_func(x), time_func(y));
@ -289,15 +292,15 @@ static int latest_time_prioq_compare(const void *a, const void *b) {
static int exit_prioq_compare(const void *a, const void *b) { static int exit_prioq_compare(const void *a, const void *b) {
const sd_event_source *x = a, *y = b; const sd_event_source *x = a, *y = b;
int r;
assert(x->type == SOURCE_EXIT); assert(x->type == SOURCE_EXIT);
assert(y->type == SOURCE_EXIT); assert(y->type == SOURCE_EXIT);
/* Enabled ones first */ /* Enabled ones first */
r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF); if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
if (r != 0) return -1;
return r; if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
return 1;
/* Lower priority values first */ /* Lower priority values first */
return CMP(x->priority, y->priority); return CMP(x->priority, y->priority);
@ -771,15 +774,14 @@ static void event_source_time_prioq_reshuffle(sd_event_source *s) {
assert(s); assert(s);
/* Called whenever the event source's timer ordering properties changed, i.e. time, accuracy, /* Called whenever the event source's timer ordering properties changed, i.e. time, accuracy,
* pending, enable state, and ratelimiting state. Makes sure the two prioq's are ordered * pending, enable state. Makes sure the two prioq's are ordered properly again. */
* properly again. */
if (s->ratelimited) if (s->ratelimited)
d = &s->event->monotonic; d = &s->event->monotonic;
else if (EVENT_SOURCE_IS_TIME(s->type)) else {
assert(EVENT_SOURCE_IS_TIME(s->type));
assert_se(d = event_get_clock_data(s->event, s->type)); assert_se(d = event_get_clock_data(s->event, s->type));
else }
return; /* no-op for an event source which is neither a timer nor ratelimited. */
prioq_reshuffle(d->earliest, s, &s->earliest_index); prioq_reshuffle(d->earliest, s, &s->earliest_index);
prioq_reshuffle(d->latest, s, &s->latest_index); prioq_reshuffle(d->latest, s, &s->latest_index);
@ -2370,6 +2372,14 @@ static int event_source_offline(
source_io_unregister(s); source_io_unregister(s);
break; break;
case SOURCE_TIME_REALTIME:
case SOURCE_TIME_BOOTTIME:
case SOURCE_TIME_MONOTONIC:
case SOURCE_TIME_REALTIME_ALARM:
case SOURCE_TIME_BOOTTIME_ALARM:
event_source_time_prioq_reshuffle(s);
break;
case SOURCE_SIGNAL: case SOURCE_SIGNAL:
event_gc_signal_data(s->event, &s->priority, s->signal.sig); event_gc_signal_data(s->event, &s->priority, s->signal.sig);
break; break;
@ -2390,11 +2400,6 @@ static int event_source_offline(
prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
break; break;
case SOURCE_TIME_REALTIME:
case SOURCE_TIME_BOOTTIME:
case SOURCE_TIME_MONOTONIC:
case SOURCE_TIME_REALTIME_ALARM:
case SOURCE_TIME_BOOTTIME_ALARM:
case SOURCE_DEFER: case SOURCE_DEFER:
case SOURCE_POST: case SOURCE_POST:
case SOURCE_INOTIFY: case SOURCE_INOTIFY:
@ -2404,9 +2409,6 @@ static int event_source_offline(
assert_not_reached("Wut? I shouldn't exist."); assert_not_reached("Wut? I shouldn't exist.");
} }
/* Always reshuffle time prioq, as the ratelimited flag may be changed. */
event_source_time_prioq_reshuffle(s);
return 1; return 1;
} }
@ -2496,11 +2498,22 @@ static int event_source_online(
s->ratelimited = ratelimited; s->ratelimited = ratelimited;
/* Non-failing operations below */ /* Non-failing operations below */
if (s->type == SOURCE_EXIT) switch (s->type) {
prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); case SOURCE_TIME_REALTIME:
case SOURCE_TIME_BOOTTIME:
case SOURCE_TIME_MONOTONIC:
case SOURCE_TIME_REALTIME_ALARM:
case SOURCE_TIME_BOOTTIME_ALARM:
event_source_time_prioq_reshuffle(s);
break;
/* Always reshuffle time prioq, as the ratelimited flag may be changed. */ case SOURCE_EXIT:
event_source_time_prioq_reshuffle(s); prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
break;
default:
break;
}
return 1; return 1;
} }
@ -2970,8 +2983,8 @@ static int event_arm_timer(
if (!d->needs_rearm) if (!d->needs_rearm)
return 0; return 0;
else
d->needs_rearm = false; d->needs_rearm = false;
a = prioq_peek(d->earliest); a = prioq_peek(d->earliest);
if (!a || a->enabled == SD_EVENT_OFF || time_event_source_next(a) == USEC_INFINITY) { if (!a || a->enabled == SD_EVENT_OFF || time_event_source_next(a) == USEC_INFINITY) {
@ -3667,8 +3680,8 @@ static int arm_watchdog(sd_event *e) {
assert(e->watchdog_fd >= 0); assert(e->watchdog_fd >= 0);
t = sleep_between(e, t = sleep_between(e,
usec_add(e->watchdog_last, (e->watchdog_period / 2)), e->watchdog_last + (e->watchdog_period / 2),
usec_add(e->watchdog_last, (e->watchdog_period * 3 / 4))); e->watchdog_last + (e->watchdog_period * 3 / 4));
timespec_store(&its.it_value, t); timespec_store(&its.it_value, t);

View File

@ -667,7 +667,7 @@ int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_
if (r == 0) if (r == 0)
return 1; /* Polkit will call us back */ return 1; /* Polkit will call us back */
r = link_reconfigure(l, /* force = */ true); r = link_reconfigure(l, true);
if (r < 0) if (r < 0)
return r; return r;
if (r > 0) { if (r > 0) {

View File

@ -1199,7 +1199,7 @@ static int link_get_network(Link *link, Network **ret) {
return -ENOENT; return -ENOENT;
} }
static int link_reconfigure_impl(Link *link, bool force) { static int link_reconfigure_internal(Link *link, bool force) {
Network *network; Network *network;
int r; int r;
@ -1267,7 +1267,7 @@ static int link_reconfigure_handler_internal(sd_netlink *rtnl, sd_netlink_messag
if (r <= 0) if (r <= 0)
return r; return r;
r = link_reconfigure_impl(link, force); r = link_reconfigure_internal(link, force);
if (r < 0) if (r < 0)
link_enter_failed(link); link_enter_failed(link);
@ -1497,6 +1497,15 @@ static int link_carrier_gained(Link *link) {
/* let's shortcut things for CAN which doesn't need most of what's done below. */ /* let's shortcut things for CAN which doesn't need most of what's done below. */
return 0; return 0;
r = wifi_get_info(link);
if (r < 0)
return r;
if (r > 0) {
r = link_reconfigure_internal(link, false);
if (r != 0)
return r;
}
if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) { if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) {
r = link_acquire_dynamic_conf(link); r = link_acquire_dynamic_conf(link);
if (r < 0) if (r < 0)
@ -1821,7 +1830,7 @@ void link_update_operstate(Link *link, bool also_update_master) {
: "") : "")
static int link_update_flags(Link *link, sd_netlink_message *message) { static int link_update_flags(Link *link, sd_netlink_message *message) {
bool link_was_lower_up, link_was_admin_up, had_carrier; bool link_was_admin_up, had_carrier;
uint8_t operstate; uint8_t operstate;
unsigned flags; unsigned flags;
int r; int r;
@ -1883,7 +1892,6 @@ static int link_update_flags(Link *link, sd_netlink_message *message) {
log_link_debug(link, "Unknown link flags lost, ignoring: %#.5x", unknown_flags_removed); log_link_debug(link, "Unknown link flags lost, ignoring: %#.5x", unknown_flags_removed);
} }
link_was_lower_up = link->flags & IFF_LOWER_UP;
link_was_admin_up = link->flags & IFF_UP; link_was_admin_up = link->flags & IFF_UP;
had_carrier = link_has_carrier(link); had_carrier = link_has_carrier(link);
@ -1892,19 +1900,6 @@ static int link_update_flags(Link *link, sd_netlink_message *message) {
link_update_operstate(link, true); link_update_operstate(link, true);
if (!link_was_lower_up && (link->flags & IFF_LOWER_UP)) {
r = wifi_get_info(link);
if (r < 0)
return r;
if (r > 0) {
/* All link information is up-to-date. So, it is not necessary to call
* RTM_GETLINK netlink method again. */
r = link_reconfigure_impl(link, /* force = */ false);
if (r < 0)
return r;
}
}
if (!link_was_admin_up && (link->flags & IFF_UP)) { if (!link_was_admin_up && (link->flags & IFF_UP)) {
log_link_info(link, "Link UP"); log_link_info(link, "Link UP");

View File

@ -216,7 +216,7 @@ static int bus_method_reload(sd_bus_message *message, void *userdata, sd_bus_err
return r; return r;
HASHMAP_FOREACH(link, manager->links) { HASHMAP_FOREACH(link, manager->links) {
r = link_reconfigure(link, /* force = */ false); r = link_reconfigure(link, false);
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -920,16 +920,7 @@ static int link_up_or_down(Link *link, bool up, link_netlink_message_handler_t c
} }
int link_down(Link *link) { int link_down(Link *link) {
int r; return link_up_or_down(link, false, link_down_handler);
assert(link);
r = link_up_or_down(link, false, link_down_handler);
if (r < 0)
return log_link_error_errno(link, r, "Failed to bring down interface: %m");
link->set_flags_messages++;
return 0;
} }
static bool link_is_ready_to_activate(Link *link) { static bool link_is_ready_to_activate(Link *link) {

View File

@ -18,9 +18,8 @@
int wifi_get_info(Link *link) { int wifi_get_info(Link *link) {
_cleanup_free_ char *ssid = NULL; _cleanup_free_ char *ssid = NULL;
enum nl80211_iftype iftype; enum nl80211_iftype iftype;
bool updated = false;
const char *type; const char *type;
int r; int r, s = 0;
assert(link); assert(link);
@ -39,26 +38,23 @@ int wifi_get_info(Link *link) {
r = wifi_get_interface(link->manager->genl, link->ifindex, &iftype, &ssid); r = wifi_get_interface(link->manager->genl, link->ifindex, &iftype, &ssid);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) if (r > 0 && link->wlan_iftype == iftype && streq_ptr(link->ssid, ssid))
iftype = link->wlan_iftype; /* Assume iftype is not changed. */ r = 0;
if (iftype == NL80211_IFTYPE_STATION) {
struct ether_addr bssid;
r = wifi_get_station(link->manager->genl, link->ifindex, &bssid);
if (r < 0)
return r;
updated = !ether_addr_equal(&link->bssid, &bssid);
link->bssid = bssid;
}
updated = updated || link->wlan_iftype != iftype;
link->wlan_iftype = iftype; link->wlan_iftype = iftype;
updated = updated || !streq_ptr(link->ssid, ssid);
free_and_replace(link->ssid, ssid); free_and_replace(link->ssid, ssid);
if (updated) { if (link->wlan_iftype == NL80211_IFTYPE_STATION) {
struct ether_addr old_bssid = link->bssid;
s = wifi_get_station(link->manager->genl, link->ifindex, &link->bssid);
if (s < 0)
return s;
if (s > 0 && memcmp(&old_bssid, &link->bssid, sizeof old_bssid) == 0)
s = 0;
}
if (r > 0 || s > 0) {
if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid) if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
log_link_info(link, "Connected WiFi access point: %s (%s)", log_link_info(link, "Connected WiFi access point: %s (%s)",
link->ssid, ETHER_ADDR_TO_STR(&link->bssid)); link->ssid, ETHER_ADDR_TO_STR(&link->bssid));

View File

@ -837,7 +837,7 @@ static void test_load_syscall_filter_set_raw(void) {
assert_se(s = hashmap_new(NULL)); assert_se(s = hashmap_new(NULL));
#if defined __NR_poll && __NR_poll >= 0 #if defined __NR_poll && __NR_poll >= 0
assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_poll + 1), INT_TO_PTR(-1)) >= 0); assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_poll + 1), INT_TO_PTR(-1)) >= 0);
#elif defined __NR_ppoll #else
assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_ppoll + 1), INT_TO_PTR(-1)) >= 0); assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_ppoll + 1), INT_TO_PTR(-1)) >= 0);
#endif #endif
@ -854,8 +854,7 @@ static void test_load_syscall_filter_set_raw(void) {
assert_se(s = hashmap_new(NULL)); assert_se(s = hashmap_new(NULL));
#if defined __NR_poll && __NR_poll >= 0 #if defined __NR_poll && __NR_poll >= 0
assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_poll + 1), INT_TO_PTR(EILSEQ)) >= 0); assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_poll + 1), INT_TO_PTR(EILSEQ)) >= 0);
#elif defined __NR_ppoll #else
assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_ppoll + 1), INT_TO_PTR(-1)) >= 0);
assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_ppoll + 1), INT_TO_PTR(EILSEQ)) >= 0); assert_se(hashmap_put(s, UINT32_TO_PTR(__NR_ppoll + 1), INT_TO_PTR(EILSEQ)) >= 0);
#endif #endif