Don't crash on systemd unit result

This commit is contained in:
Patrick Nicolas
2026-10-25 08:57:52 +01:00
parent b6bc602c5b
commit edb1bf25ad
+4 -2
View File
@@ -162,9 +162,11 @@ void systemd_units_manager::on_unit_result(
void * self_)
{
auto self = (systemd_units_manager *)(self_);
std::string_view state = unit_unit_get_active_state(unit);
const char * state = unit_unit_get_active_state(unit);
if (state == nullptr)
return;
bool empty = self->units.empty();
if (state == "inactive" or state == "failed")
if (state == std::string_view("inactive") or state == std::string_view("failed"))
std::erase_if(self->units, [&](auto & o) { return o.get() == unit; });
if (self->state_changed_cb and self->units.empty() and not empty)
self->state_changed_cb();