Skip to content

Support rotating log buffers - #592

Open
ziyao233 wants to merge 4 commits into
davmac314:masterfrom
ziyao233:service/rotate-buffered-log
Open

ziyao233 wants to merge 4 commits into
davmac314:masterfrom
ziyao233:service/rotate-buffered-log

Conversation

@ziyao233

@ziyao233 ziyao233 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This series implements a circular buffer for buffering service log, providing a simple API to append to it, and another in-place API to linearize the buffer to be sent to external programs, etc. Only appending to the buffer when it doesn't reach the maximum size might involve memory allocation. The new append API introduces extra overhead of copying, but is much easier to use, with which related code is simplified.

For sake of simplicity, the first patch modifies service loading code, to reject log-buffer-size = 0 settings. This possibly breaks existing services, but I don't think such settings make much sense, since it means all output from the service would be discarded, which could (and IMO, should) be achieved by log-type = none.

Zero log-buffer-size makes no sense. For discarding output, using "none"
for log-type would be sufficient. Reject such settings, which would
simplify later buffered-logging improvements, and mention this
limitation in the manual,
- Restarting a service, whose log buffer ends with a correct EOL, should
  yield no empty line (duplicated newline) before the restarting
  message, i.e., "dinit: note: service restarted\n" shouldn't be
  prefixed with '\n'.
- Restarting a service, whose log buffer is empty, should yield no
  restarting message at all.
Implement a circular log buffer in base_process_service. It provides the
following functionality,

- Copy data and append it to the buffer (log_buffer_append), possibly
  fails for allocation errors if the buffer fails to grow to
  log-buffer-size, which should be okay since the previous code fails
  in this case, too.
- Linearize the buffer, so it could be randomly accessed by most
  external APIs (linearize_log_buffer).

Comparing to the previous truncating implementation, appending to the
buffer now requires an extra copy since the buffer couldn't be randomly
written, but surrounding code gets simplified.

Integration tests triggering buffer rotation are added along the way.

Closes: davmac314#315
Wrap invocation of dinitctl in lambdas, to make the test cases easier to
read.
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.

1 participant