nbd-tester-client: ignore SIGPIPE so we pick up and print the error
[nbd.git] / nbd-tester-client.c
index ed9214e..fee2d87 100644 (file)
@@ -1183,10 +1183,13 @@ int main(int argc, char**argv) {
        int testflags=0;
        testfunc test = throughput_test;
 
        int testflags=0;
        testfunc test = throughput_test;
 
+       /* Ignore SIGPIPE as we want to pick up the error from write() */
+       signal (SIGPIPE, SIG_IGN);
+
        if(argc<3) {
                g_message("%d: Not enough arguments", (int)getpid());
                g_message("%d: Usage: %s <hostname> <port>", (int)getpid(), argv[0]);
        if(argc<3) {
                g_message("%d: Not enough arguments", (int)getpid());
                g_message("%d: Usage: %s <hostname> <port>", (int)getpid(), argv[0]);
-               g_message("%d: Or: %s <hostname> -N <exportname>", (int)getpid(), argv[0]);
+               g_message("%d: Or: %s <hostname> -N <exportname> [<port>]", (int)getpid(), argv[0]);
                exit(EXIT_FAILURE);
        }
        logging();
                exit(EXIT_FAILURE);
        }
        logging();
@@ -1199,7 +1202,6 @@ int main(int argc, char**argv) {
                                                nonopt++;
                                                break;
                                        case 1:
                                                nonopt++;
                                                break;
                                        case 1:
-                                               if(want_port)
                                                p=(strtol(argv[2], NULL, 0));
                                                if(p==LONG_MIN||p==LONG_MAX) {
                                                        g_critical("Could not parse port number: %s", strerror(errno));
                                                p=(strtol(argv[2], NULL, 0));
                                                if(p==LONG_MIN||p==LONG_MAX) {
                                                        g_critical("Could not parse port number: %s", strerror(errno));
@@ -1210,7 +1212,9 @@ int main(int argc, char**argv) {
                                break;
                        case 'N':
                                name=g_strdup(optarg);
                                break;
                        case 'N':
                                name=g_strdup(optarg);
-                               p = 10809;
+                               if(!p) {
+                                       p = 10809;
+                               }
                                want_port = false;
                                break;
                        case 't':
                                want_port = false;
                                break;
                        case 't':