Changes:
- Replaces unchecked
fcntl(fd, F_SETFD, flags);
with a version that checks the return value. - Throws
OSError
on failure with an appropriate error message.
Motivation:
Proper error handling is critical in system-level code to avoid silent failures, especially when setting file descriptor flags like FD_CLOEXEC
. This fix ensures robustness and helps catch configuration issues early during process setup.
Test coverage
No functional change beyond improved error propagation, but this section of code is indirectly exercised by any subprocess-related integration or functional tests. Consider adding a unit test for set_clo_on_exec
in the future for completeness.