Add inetd mode testing to the suite
authorfelix <felix.von.s@posteo.de>
Sun, 1 Apr 2018 16:12:49 +0000 (18:12 +0200)
committerfelix <felix.von.s@posteo.de>
Tue, 3 Apr 2018 14:36:43 +0000 (16:36 +0200)
tests/run/Makefile.am
tests/run/nbd-tester-client.c
tests/run/simple_test

index 6467ca2..e76d72f 100644 (file)
@@ -4,7 +4,7 @@ else
 TLSSRC =
 endif
 TESTS_ENVIRONMENT=$(srcdir)/simple_test
-TESTS = cfg1 cfgmulti cfgnew cfgsize write flush integrity dirconfig list \
+TESTS = cfg1 cfgmulti cfgnew cfgsize write flush integrity dirconfig list inetd \
        rowrite tree rotree unix integrityhuge handshake tls tlshuge tlswrongcert
 check_PROGRAMS = nbd-tester-client
 ## Various Automake versions don't play nice with files in parent
@@ -44,6 +44,7 @@ rowrite:
 tree:
 rotree:
 unix:
+inetd:
 handshake:
 tls:
 tlshuge:
index 13bf033..722eb49 100644 (file)
@@ -633,6 +633,35 @@ end:
        return sock;
 }
 
+int setup_inetd_connection(gchar **argv)
+{
+       int sv[2];
+       pid_t child;
+
+       if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
+               strncpy(errstr, strerror(errno), errstr_len);
+               return -1;
+       }
+
+       child = vfork();
+       if (child == 0) {
+               dup2(sv[0], 0);
+               close(sv[0]);
+               close(sv[1]);
+               execvp(argv[0], argv);
+       } else if (child == -1) {
+               close(sv[0]);
+               close(sv[1]);
+               strncpy(errstr, strerror(errno), errstr_len);
+               return -1;
+       }
+
+       close(sv[0]);
+       setmysockopt(sv[1]);
+
+       return sv[1];
+}
+
 int close_connection(int sock, CLOSE_TYPE type)
 {
        struct nbd_request req;
@@ -1687,7 +1716,7 @@ typedef int (*testfunc) (char *, int, char, int);
 int main(int argc, char **argv)
 {
        gchar *hostname = NULL, *unixsock = NULL;
-       long int p = 0;
+       long int p = 10809;
        char *name = NULL;
        int sock = -1;
        int c;
@@ -1714,16 +1743,13 @@ int main(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
        logging(MY_NAME);
-       while ((c = getopt(argc, argv, "FN:t:owfilu:hC:K:A:H:")) >= 0) {
+       while ((c = getopt(argc, argv, "FN:t:owfilu:hC:K:A:H:I")) >= 0) {
                switch (c) {
                case 1:
                        handle_nonopt(optarg, &hostname, &p);
                        break;
                case 'N':
                        name = g_strdup(optarg);
-                       if (!p) {
-                               p = 10809;
-                       }
                        break;
                case 'F':
                        testflags |= TEST_EXPECT_ERROR;
@@ -1743,6 +1769,9 @@ int main(int argc, char **argv)
                case 'f':
                        testflags |= TEST_FLUSH;
                        break;
+               case 'I':
+                       p = -1;
+                       break;
                case 'i':
                        test = integrity_test;
                        break;
@@ -1778,8 +1807,10 @@ int main(int argc, char **argv)
                }
        }
 
-       while (optind < argc) {
-               handle_nonopt(argv[optind++], &hostname, &p);
+       if (p != -1) {
+               while (optind < argc) {
+                       handle_nonopt(argv[optind++], &hostname, &p);
+               }
        }
 
        if (keyfile && !certfile)
@@ -1792,8 +1823,10 @@ int main(int argc, char **argv)
                sock = setup_inet_connection(hostname, p);
        } else if (unixsock != NULL) {
                sock = setup_unix_connection(unixsock);
+       } else if (p == -1) {
+               sock = setup_inetd_connection(argv + optind);
        } else {
-               g_error("need a hostname or a unix domain socket!");
+               g_error("need a hostname, a unix domain socket or inetd-mode command line!");
                return -1;
        }
 
index c45d522..2df54fb 100755 (executable)
@@ -24,8 +24,6 @@ cleanup() {
                if [ ! -z "$PID" ]
                then
                        kill $PID || true
-               else
-                       echo "E: Could not clean up!"
                fi
        fi
        if [ -z "$cleanup" ]
@@ -294,6 +292,16 @@ EOF
                ./nbd-tester-client -N export1 -u ${tmpdir}/unix.sock
                retval=$?
                ;;
+       */inetd)
+               cat >${conffile} <<EOF
+[generic]
+       port = 0
+[export1]
+       exportname = ${tmpnam}
+EOF
+               ./nbd-tester-client -N export1 -I -- ../../nbd-server -d -C ${conffile}
+               retval=$?
+               ;;
        */handshake)
                # Test negotiation handshake
                cat >${conffile} <<EOF