proclib: fix process_open leaving pipes open on error, shrink code
commitfb50a2c708ef017edcd31693bd31646916843db2
authorrofl0r <rofl0r@users.noreply.github.com>
Sun, 7 Feb 2021 23:17:36 +0000 (7 23:17 +0000)
committerrofl0r <rofl0r@users.noreply.github.com>
Sun, 7 Feb 2021 23:17:36 +0000 (7 23:17 +0000)
treec779ecbcbd45e97d21ec402ab20e9591b96f6b17
parent011499cb91064c9ed54e6e9f30bf782baf478bd4
proclib: fix process_open leaving pipes open on error, shrink code

if process_open() failed (e.g. due to missing +x mode) the 3 fds
used for communication stayed open. this has now been changed to
match the example code in the #ifdef TEST part, e.g. on failure all
fds are closed and the caller can just go on without calling
process_close().
additionally the API has changed and the 3 fd members in the struct
turned into an array, which makes it easier to iterate over them.
the code has been modified to use loops for all the setup steps,
which results in tighter code in the binary and in the source, at
the cost of readability.
the test code has been adapted and now calls to awk so anyone should
be able to try it out.
include/proclib.h
src/proclib/process.c