Skip to content

Commit b56bf21

Browse files
committed
doc: Add comments for socket descriptor handling when forking
1 parent c1b4ab4 commit b56bf21

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/mp/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ int SpawnProcess(int& pid, FdToArgsFn&& fd_to_args)
110110
if (pid == -1) {
111111
throw std::system_error(errno, std::system_category(), "fork");
112112
}
113+
// Parent process closes the descriptor for socket 0, child closes the descriptor for socket 1.
113114
if (close(fds[pid ? 0 : 1]) != 0) {
114115
throw std::system_error(errno, std::system_category(), "close");
115116
}
116117
if (!pid) {
118+
// Child process must close all potentially open descriptors, except socket 0.
117119
int maxFd = MaxFd();
118120
for (int fd = 3; fd < maxFd; ++fd) {
119121
if (fd != fds[0]) {

0 commit comments

Comments
 (0)