Expose through CMake directives, the name of the project so that package managers such as
CPM (https://github.com/cpm-cmake/CPM.cmake) could consume this library cleanly
It's useful to be able to know the exit code of the process when it
fails with a non-zero exit code.
To get this to work, I had to fix a bug in the implementation of
check_output. Previously, check_output would call both `p.communicate()`
and `p.poll()`. The former has the effect of waiting for EOF on the
input and then waiting for the child to exit, reaping it with
`waitpid(2)`. Unfortunately, `p.poll()` was hoping to be able to also
use `waitpid(2)` to retrieve the exit code of the process. But since the
child had already been reaped, the given pid no longer existed, and thus
`waitpid(2)` would return `ECHILD`.
Luckily the call to `p.poll()` is unnecessary, as the process already
provides `p.retcode()` for retrieving the exit code.
While this is header-only, and users are expected
to download the header and commit it to their project, it's better to
have unique namespace for the header by default.
This has two reasons:
1. I wish to enable installing it with conan.io, and want to reduce
the possibility for namespace clashes. The term "subprocess" is
pretty overloaded.
2. Currently the README and the CMakeLists differ in their include
path, it's better to be consistent, even though users can put it
wherever they please in their project.
Since most users are using it as header only anyway, I don't think it'd
make much diference.
Co-authored-by: Elazar Leibovich <elazar.leibovich@nextsilicon.com>
* Fixed: forked subprocess not exited if execve failed
In lengthy processes (daemons, etc) this bug keeps open this subprocess. The subprocess continues to work (parallel to parent process) from after failed command start
* Fixed: deadlock on using multithreaded application
For example if application uses spdlog logger library and set spdlog::flush_every(std::chrono::seconds(1)); then it starts it's own thread which flushes logs every 1 second. In this case if execve failed to execute given command, then parent and subprocess deadlocked.
C++11 started to deprecate the use of throw function identifiers. In
C++17, this header no longer compiles due to the deprecation.
Signed-off-by: Ben Dang <me@bdang.it>
1. When more than 2 streams are piped, we use threads to read/write data
parallely. In this scenariod read_atmost_n API was being used instead of
read_all.
2. Another issue with check_output argument validation fixed.