]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (test_mkfds) monitor stdin by default
authorMasatake YAMATO <yamato@redhat.com>
Thu, 31 Aug 2023 15:56:06 +0000 (00:56 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 3 Sep 2023 21:15:30 +0000 (06:15 +0900)
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 <yamato@redhat.com>
tests/helpers/test_mkfds.c
tests/ts/lsfd/option-inet
tests/ts/lsfd/option-summary

index d9b95df54615454116d0b390d7cfafb5b0966aae..8118b0f900436e033c8098de5841771dd03d073d 100644 (file)
@@ -83,6 +83,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out, int status)
        fputs(" -I, --parameters <factory>    list parameters the factory takes\n", out);
        fputs(" -r, --comm <name>             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)
index b0910f230cfb139b9cfc44b0c353a759bdf81b1e..7ca88375165cc4ecfd44581fafabf307c286fe84 100755 (executable)
@@ -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}"
index 64bf54ba1c8c7ee23f83a101f40f3752b33d6669..9813901b31d6241c08405f76c80e125c5c5a752b 100755 (executable)
@@ -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}"