From: Masatake YAMATO Date: Thu, 31 Aug 2023 15:56:06 +0000 (+0900) Subject: tests: (test_mkfds) monitor stdin by default X-Git-Tag: v2.40-rc1~253^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=618a88b51e8fd3489033517db9987a6231a8f1fe;p=thirdparty%2Futil-linux.git tests: (test_mkfds) monitor stdin by default After making file descriptors as specified in arguments, test_mkfds waits for an event with pselect. When test_mkfds gets the event, it exits. The original code monitored stdin when the test_mkfds process ran in the foreground. However, monitoring stdin is useful even when it runs in the background. ts/lsfd/mkfds-* test cases run test_mkfds as a co-process. So the test cases can terminate their test_mkfds processes with echo command if the processes monitor stdin. This change also adds -X/--dont-monitor-stdin option. As the name shows, with the option, test_mkfds doesn't monitor stdin as before. Some test cases run test_mkfds directly. In such a case, tests/functions.sh may connect stdin of test_mkfds to /dev/null. /dev/null is always ready to be read. Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index d9b95df546..8118b0f900 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -83,6 +83,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out, int status) fputs(" -I, --parameters list parameters the factory takes\n", out); fputs(" -r, --comm rename self\n", out); fputs(" -q, --quiet don't print pid(s)\n", out); + fputs(" -X, --dont-monitor-stdin don't monitor stdin when pausing\n", out); fputs(" -c, --dont-pause don't pause after making fd(s)\n", out); fputs("\n", out); @@ -3733,16 +3734,14 @@ pidfd_open(pid_t pid _U_, unsigned int flags _U_) } #endif -static void wait_event(void) +static void wait_event(bool monitor_stdin) { 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()) { + if (monitor_stdin) { n = 1; FD_SET(0, &readfds); } @@ -3762,18 +3761,20 @@ int main(int argc, char **argv) bool quiet = false; bool cont = false; void *data; + bool monitor_stdin = true; static const struct option longopts[] = { { "list", no_argument, NULL, 'l' }, { "parameters", required_argument, NULL, 'I' }, { "comm", required_argument, NULL, 'r' }, { "quiet", no_argument, NULL, 'q' }, + { "dont-monitor-stdin", no_argument, NULL, 'X' }, { "dont-puase", no_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 }, }; - while ((c = getopt_long(argc, argv, "lhqcI:r:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "lhqcI:r:X", longopts, NULL)) != -1) { switch (c) { case 'h': usage(stdout, EXIT_SUCCESS); @@ -3792,6 +3793,9 @@ int main(int argc, char **argv) case 'r': rename_self(optarg); break; + case 'X': + monitor_stdin = false; + break; default: usage(stderr, EXIT_FAILURE); } @@ -3856,7 +3860,7 @@ int main(int argc, char **argv) } if (!cont) - wait_event(); + wait_event(monitor_stdin); for (int i = 0; i < factory->N + factory->EX_N; i++) if (fdescs[i].fd >= 0 && fdescs[i].close) diff --git a/tests/ts/lsfd/option-inet b/tests/ts/lsfd/option-inet index b0910f230c..7ca8837516 100755 --- a/tests/ts/lsfd/option-inet +++ b/tests/ts/lsfd/option-inet @@ -36,13 +36,13 @@ FIFO=./test_mkfds-option-inet.fifo ts_finalize "failed in creating a fifo" fi - "$TS_HELPER_MKFDS" tcp 3 4 5 server-port=34567 client-port=23456 > "${FIFO}" & + "$TS_HELPER_MKFDS" -X tcp 3 4 5 server-port=34567 client-port=23456 > "${FIFO}" & if ! read PID0 < "${FIFO}"; then rm "${FIFO}" ts_finalize "$TS_HELPER_MKFDS tcp...doesn't report its pid" fi - "$TS_HELPER_MKFDS" tcp6 3 4 5 server-port=34567 client-port=23456 > "${FIFO}" & + "$TS_HELPER_MKFDS" -X tcp6 3 4 5 server-port=34567 client-port=23456 > "${FIFO}" & if ! read PID1 < "${FIFO}"; then kill -CONT "${PID0}" wait "${PID0}" @@ -50,7 +50,7 @@ FIFO=./test_mkfds-option-inet.fifo ts_finalize "$TS_HELPER_MKFDS tcp6...doesn't report its pid" fi - "$TS_HELPER_MKFDS" ro-regular-file 3 file=/etc/passwd > "${FIFO}" & + "$TS_HELPER_MKFDS" -X ro-regular-file 3 file=/etc/passwd > "${FIFO}" & if ! read PID2 < "${FIFO}"; then kill -CONT "${PID0}" "${PID1}" wait "${PID0}" "${PID1}" @@ -58,7 +58,7 @@ FIFO=./test_mkfds-option-inet.fifo ts_finalize "$TS_HELPER_MKFDS ro-regular-file...doesn't report its pid" fi - "$TS_HELPER_MKFDS" udp 3 4 server-port=34567 client-port=23456 server-do-bind=1 client-do-bind=1 client-do-connect=1 > "${FIFO}" & + "$TS_HELPER_MKFDS" -X udp 3 4 server-port=34567 client-port=23456 server-do-bind=1 client-do-bind=1 client-do-connect=1 > "${FIFO}" & if ! read PID3 < "${FIFO}"; then kill -CONT "${PID0}" "${PID1}" "${PID2}" wait "${PID0}" "${PID1}" "${PID2}" @@ -66,7 +66,7 @@ FIFO=./test_mkfds-option-inet.fifo ts_finalize "$TS_HELPER_MKFDS udp...doesn't report its pid" fi - "$TS_HELPER_MKFDS" udp6 3 4 lite=1 server-port=34567 client-port=23456 server-do-bind=1 client-do-bind=1 client-do-connect=1 > "${FIFO}" & + "$TS_HELPER_MKFDS" -X udp6 3 4 lite=1 server-port=34567 client-port=23456 server-do-bind=1 client-do-bind=1 client-do-connect=1 > "${FIFO}" & if ! read PID4 < "${FIFO}"; then kill -CONT "${PID0}" "${PID1}" "${PID2}" "${PID3}" wait "${PID0}" "${PID1}" "${PID2}" "${PID3}" diff --git a/tests/ts/lsfd/option-summary b/tests/ts/lsfd/option-summary index 64bf54ba1c..9813901b31 100755 --- a/tests/ts/lsfd/option-summary +++ b/tests/ts/lsfd/option-summary @@ -35,14 +35,14 @@ PIDS= PID= for i in {1..10}; do - "$TS_HELPER_MKFDS" -q ro-regular-file $FD file=$F_GROUP & + "$TS_HELPER_MKFDS" -X -q ro-regular-file $FD file=$F_GROUP & PID=$! PIDS="${PIDS} ${PID} " lsfd_wait_for_pausing "${PID}" done for i in {1..3}; do - "$TS_HELPER_MKFDS" -q ro-regular-file $FD file=$F_PASSWD & + "$TS_HELPER_MKFDS" -X -q ro-regular-file $FD file=$F_PASSWD & PID=$! PIDS="${PIDS} ${PID} " lsfd_wait_for_pausing "${PID}"