add FD_CLOEXEC to --exec: needed for multiple uses of --exec v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 11 Jan 2020 00:58:35 +0100
branchv_0
changeset 30 56409232e1a1
parent 29 6f15f18d2abf
child 31 c64e1588f428
add FD_CLOEXEC to --exec: needed for multiple uses of --exec without FD_CLOEXEC the second forked/executed process will hold copy of the input FD of the first sub-process which will be waiting for input messages (hang)
src/SubProcess.cpp
--- a/src/SubProcess.cpp	Sat Jan 11 00:56:51 2020 +0100
+++ b/src/SubProcess.cpp	Sat Jan 11 00:58:35 2020 +0100
@@ -142,6 +142,8 @@
 			// Parent process
 			closeOrThrow(subInputReaderFD);
 			closeOrThrow(subOutputWriterFD);
+			fcntl(subInputWriterFD, F_SETFD, FD_CLOEXEC);
+			fcntl(subOutputReaderFD, F_SETFD, FD_CLOEXEC);
 			return new SubProcessImpl(subPid, subInputWriterFD, subOutputReaderFD);
 		}
 	}