Skip to content

ENT-14195 1. Refactored cf-reactor event handling with one unified interface - #6353

Open
victormlg wants to merge 1 commit into
cfengine:masterfrom
victormlg:event-handling-1-refactor
Open

ENT-14195 1. Refactored cf-reactor event handling with one unified interface#6353
victormlg wants to merge 1 commit into
cfengine:masterfrom
victormlg:event-handling-1-refactor

Conversation

@victormlg

Copy link
Copy Markdown
Contributor

Rather than exposing the raw file-descriptor bookkeeping required for select(2), we introduce a unified interface that serves both the reactor-plugin and event-driven code paths. This is achieved by encapsulating all relevant state in a context struct, ReactorContext:

typedef struct ReactorContext
{
    int *all_fds; // heap allocated array of fds
    size_t all_fds_capacity; // total number of fds. number of nova fds + number of event fds 
    size_t num_nova_fds; // this is returned by the reactor-plugin
    size_t num_fds; // this is 1
    // the first (num_nova_fds - 1) slots in the array are reserved for the reactor-plugin, the last one is reserved for the event driven code.

    fd_set readfds;
} ReactorContext;
  • ReactorContextInitialize(): initializes the reactor-plugin and event-driven code. Wraps ReactorNovaInitialize()
  • ReactorContextSetupFileDescriptors(): populates readfds with the file descriptors to monitor, prior to the select() call.
  • ReactorContextHandleEvents(): iterates over the file descriptors and dispatches the appropriate action based on which ones were signaled as ready. Wraps ReactorNovaHandleTimeout and ReactorNovaHandleEvents().
  • ReactorContextFinalize(): releases the daemon's associated resources. Wraps ReactorNovaFinalize().

Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg
victormlg requested a review from larsewi September 7, 2026 11:53
@victormlg victormlg changed the title Refactored cf-reactor event handling with one unified interface ENT-14195 1. Refactored cf-reactor event handling with one unified interface Sep 7, 2026

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if we stored FDs in a dynamic list instead (e.g., Seq)? Furthermore, maybe the FD itself could be wrapped in a struct with flags to tell what type of FD it is, and whether or not it is owned by any external plugin.

Comment thread cf-reactor/cf-reactor.h
* `all_fds` is a single flat array shared by every event source the daemon
* watches. Nova's fds always occupy the first `num_nova_fds` slots (Nova
* owns that sub-range and is the only thing allowed to populate it); any
* other event source (currently just the watcher subsystem, see watcher.h)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did we not recently remove the watcher code you are referencing here?

Comment thread cf-reactor/cf-reactor.h
* No other file needs to know how many event sources exist or in what
* order their fds appear.
*/
typedef struct ReactorContext

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like this belongs in reactor_context.h. What is the reason for having it here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants