libvmz: clarify fd ownership and serial output configuration #31

Open
opened 2026-05-22 10:38:21 +00:00 by rc · 0 comments
Owner

Problem:

  • FD ownership is unclear for read_pipe_fd.
  • Swift creates FileHandle(fileDescriptor:closeOnDealloc:) with closeOnDealloc true during create.
  • Serial output is hardcoded to FileHandle.standardOutput rather than being part of config.

Why this is bad:

  • C callers need exact ownership rules for file descriptors.
  • If libvmz takes ownership, the header should say so. If not, the implementation should duplicate the fd.
  • Hardcoded stdout makes the library less reusable and hard to embed.

Suggested fix:

  • Decide whether libvmz borrows, duplicates, or takes ownership of serial input fds and document it precisely.
  • Prefer duplicating caller-provided fds internally, so callers keep ownership of their descriptors.
  • Add a serial output fd to config or a separate serial configuration API.

Relevant code:

  • lib/libvmz.h: read_pipe_fd docs do not define ownership transfer.
  • lib/libvmz.swift: buildConfiguration uses closeReadPipeOnDealloc and hardcodes FileHandle.standardOutput.
Problem: - FD ownership is unclear for read_pipe_fd. - Swift creates FileHandle(fileDescriptor:closeOnDealloc:) with closeOnDealloc true during create. - Serial output is hardcoded to FileHandle.standardOutput rather than being part of config. Why this is bad: - C callers need exact ownership rules for file descriptors. - If libvmz takes ownership, the header should say so. If not, the implementation should duplicate the fd. - Hardcoded stdout makes the library less reusable and hard to embed. Suggested fix: - Decide whether libvmz borrows, duplicates, or takes ownership of serial input fds and document it precisely. - Prefer duplicating caller-provided fds internally, so callers keep ownership of their descriptors. - Add a serial output fd to config or a separate serial configuration API. Relevant code: - lib/libvmz.h: read_pipe_fd docs do not define ownership transfer. - lib/libvmz.swift: buildConfiguration uses closeReadPipeOnDealloc and hardcodes FileHandle.standardOutput.
Sign in to join this conversation.
No labels
highprio
lowprio
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rc/vmz#31
No description provided.