Skip to content

Cleanup macOS epoll shim#564

Merged
mtjhrc merged 4 commits intocontainers:mainfrom
nirs:cleanup-epoll-shim
Feb 27, 2026
Merged

Cleanup macOS epoll shim#564
mtjhrc merged 4 commits intocontainers:mainfrom
nirs:cleanup-epoll-shim

Conversation

@nirs
Copy link
Contributor

@nirs nirs commented Feb 26, 2026

Clean up the wait() function in the macOS epoll/kevent shim to make it
easier to read and debug.

Changes

  1. Return early on errors -- handle kevent() errors upfront instead
    of matching at the end, making the flow clearer.

  2. Cast kevent count to usize before the loop -- eliminates repeated
    i as usize casts on every array access.

  3. Improve kevent debug log -- log processed event info (READ/WRITE,
    fd, data) instead of the raw kevent struct, making debug output
    immediately useful.

Example logs

[2026-02-26T18:28:23.856913Z DEBUG utils::macos::epoll] kevent: WRITE fd=3 data=66560
[2026-02-26T18:28:23.856923Z DEBUG utils::macos::epoll] kevent: READ fd=3 data=3539700
[2026-02-26T18:28:23.859383Z DEBUG utils::macos::epoll] kevent: READ fd=83 data=8

Includes the timestamp commit from #556 for better logging.

nirs added 4 commits February 27, 2026 01:06
The default second-resolution timestamps make it impossible to
understand the timing of events. Use format_timestamp_micros() in
both logger init paths (krun_set_log_level and krun_init_log) so
log output shows microsecond precision.

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
Make the code more clear, easier to follow by handling error from
kevent() early.

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
The repeated `i as usize` casts on every array access made the
loop harder to read.

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
Previously we logged the raw event before processing it. Now we process
the event and log a more clear and easier to understand message. With
this can tell if we woke up for READ or WRITE event and we the log make
the values more clear.

Example logs:

    [2026-02-26T18:28:23.856913Z DEBUG utils::macos::epoll] kevent: WRITE fd=3 data=66560
    [2026-02-26T18:28:23.856923Z DEBUG utils::macos::epoll] kevent: READ fd=3 data=3539700
    [2026-02-26T18:28:23.859383Z DEBUG utils::macos::epoll] kevent: READ fd=83 data=8

Assisted-by: Cursor/Claude Opus 4.6
Signed-off-by: Nir Soffer <nirsof@gmail.com>
@nirs nirs force-pushed the cleanup-epoll-shim branch from ef99154 to 99adc35 Compare February 26, 2026 23:06
@mtjhrc
Copy link
Collaborator

mtjhrc commented Feb 27, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request provides a good cleanup of the wait() function in the macOS epoll shim, enhancing readability and debuggability. The changes, such as returning early on errors and improving log messages, are positive improvements. Additionally, enabling microsecond-precision timestamps for logging is a valuable addition. I have one suggestion to refactor the new event_name function to be more idiomatic and maintainable.

Copy link
Collaborator

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mtjhrc mtjhrc merged commit 9e28ccd into containers:main Feb 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants