From: Masatake YAMATO Date: Fri, 23 Sep 2022 17:38:24 +0000 (+0900) Subject: tests: (mkfds) quit when a byte is given via standard input X-Git-Tag: v2.39-rc1~505^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=caa97697a7c5ff3545d6aabdbf102b3f6a2d2608;p=thirdparty%2Futil-linux.git tests: (mkfds) quit when a byte is given via standard input The original code monitored only SIGCONT. It is suitable for using the command from a test script. Monitoring standard input is helpful for developing a new factory interactively. Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 994da2b77e..ba6e287939 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1056,6 +1057,27 @@ pidfd_open(pid_t pid _U_, unsigned int flags _U_) } #endif +static void wait_event(void) +{ + fd_set readfds; + sigset_t sigset; + int n = 0; + + FD_ZERO(&readfds); + /* Monitor the standard input only when the process + * is in foreground. */ + if (tcgetpgrp(STDIN_FILENO) == getpgrp()) { + n = 1; + FD_SET(0, &readfds); + } + + sigemptyset(&sigset); + + if (pselect(n, &readfds, NULL, NULL, NULL, &sigset) < 0 + && errno != EINTR) + errx(EXIT_FAILURE, _("failed in pselect")); +} + int main(int argc, char **argv) { int c; @@ -1150,7 +1172,7 @@ int main(int argc, char **argv) } if (!cont) - pause(); + wait_event(); for (int i = 0; i < factory->N + factory->EX_N; i++) if (fdescs[i].fd >= 0 && fdescs[i].close)