System: add binary subprocess session (#44)
This commit is contained in:
1 parent
b3c566ed4d
commit
540c3d9117
4 files changed
+1222
No files matched your search
@@ -245,6 +245,31 @@ int mode_grandchild_ignore_sigterm(int argc, char** argv)
|
||||
::_exit(0);
|
||||
}
|
||||
|
||||
int mode_descendant_holds_stdout(int argc, char** argv)
|
||||
{
|
||||
std::int64_t hold_ms = 5000;
|
||||
if (argc >= 3 && !parse_i64(argv[2], hold_ms)) {
|
||||
return usage_error("descendant-holds-stdout duration must be an integer");
|
||||
}
|
||||
if (hold_ms < 0) {
|
||||
hold_ms = 0;
|
||||
}
|
||||
const pid_t descendant = ::fork();
|
||||
if (descendant < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (descendant == 0) {
|
||||
// Keep the inherited stdout write end open while ignoring graceful
|
||||
// termination, so the parent's reader sees no EOF.
|
||||
std::signal(SIGTERM, SIG_IGN);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{hold_ms});
|
||||
::_exit(0);
|
||||
}
|
||||
static constexpr char kReady[] = "ready\n";
|
||||
(void)write_all_fd(STDOUT_FILENO, kReady, sizeof(kReady) - 1);
|
||||
::_exit(0);
|
||||
}
|
||||
|
||||
int mode_simultaneous_io(int argc, char** argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
@@ -539,6 +564,9 @@ int main(int argc, char** argv)
|
||||
if (mode == "grandchild-ignore-sigterm") {
|
||||
return mode_grandchild_ignore_sigterm(argc, argv);
|
||||
}
|
||||
if (mode == "descendant-holds-stdout") {
|
||||
return mode_descendant_holds_stdout(argc, argv);
|
||||
}
|
||||
if (mode == "simultaneous-io") {
|
||||
return mode_simultaneous_io(argc, argv);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user