Skip to content

Commit

Permalink
fix: prevent installing a time event, when there's no need for a timeout
Browse files Browse the repository at this point in the history
See #324 for discussion
  • Loading branch information
hellow554 authored and sangelovic committed Oct 4, 2023
1 parent 0a1606d commit e3070b9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ int Connection::onSdEventPrepare(sd_event_source */*s*/, void *userdata)
auto* sdTimeEventSource = static_cast<sd_event_source*>(connection->sdEvent_->sdTimeEventSource.get());
r = sd_event_source_set_time(sdTimeEventSource, static_cast<uint64_t>(sdbusPollData.timeout.count()));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set timeout for time event source", -r);
r = sd_event_source_set_enabled(sdTimeEventSource, SD_EVENT_ON);
// In case the timeout is infinite, we disable the timer in the sd_event loop.
// This prevents a syscall error, where `timerfd_settime` returns `EINVAL`,
// because the value is too big. See #324 for details
r = sd_event_source_set_enabled(sdTimeEventSource, sdbusPollData.timeout != sdbusPollData.timeout.max() ? SD_EVENT_ONESHOT : SD_EVENT_OFF);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to enable time event source", -r);

return 1;
Expand Down

0 comments on commit e3070b9

Please sign in to comment.