logo

pts

Fake a pseudo-terminal for testsuites
commit: b961ecfc9eadb5ecb3b4e4bed1ebbfcb1f6f1f2f
parent 37076a6e6d80e0f3d32680fee3342ac14c7e8467
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  2 Jun 2024 07:03:27 +0200

Handle SIGCHLD

Diffstat:

Mpts.c21+++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/pts.c b/pts.c @@ -12,6 +12,18 @@ #include <poll.h> #include <unistd.h> // execvp, dup2 #include <sys/wait.h> +#include <signal.h> + +static int child_status = 0; +static pid_t pid = -1; + +static void +handle_sigchld(int sig) +{ + (void)sig; + waitpid(pid, &child_status, WNOHANG); + exit(WEXITSTATUS(child_status)); +} int main(int argc, char *argv[]) @@ -43,7 +55,7 @@ main(int argc, char *argv[]) return 1; } - pid_t pid = fork(); + pid = fork(); if(pid < 0) { fprintf(stderr, "pts: Fork failed: %s\n", strerror(errno)); @@ -64,8 +76,13 @@ main(int argc, char *argv[]) } }; + if(signal(SIGCHLD, handle_sigchld) == SIG_ERR) + { + fprintf(stderr, "timeout: Failed registering handler for SIGCHLD: %s\n", strerror(errno)); + return 1; + } + // parent - int child_status = 0; do { int ret = poll(pfds, nfds, -1); if(ret < 0)