tools/virtio: virtio_test -h,--help should return directly
authorRong Tao <rongtao@cestc.cn>
Thu, 9 Mar 2023 08:42:50 +0000 (16:42 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 21 Apr 2023 07:02:30 +0000 (03:02 -0400)
When we get help information, we should return directly, and we should not
execute test cases. Move the exit() directly into the help() function and
remove it from case '?'.

Signed-off-by: Rong Tao <rongtao@cestc.cn>
Message-Id: <tencent_822CEBEB925205EA1573541CD1C2604F4805@qq.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
tools/virtio/virtio_test.c

index 280c6f8ee297af954d907d5cafd5dd4756d72ea5..028f54e6854a824acd0b6c8c85d5d8e412c35846 100644 (file)
@@ -327,7 +327,7 @@ const struct option longopts[] = {
        }
 };
 
-static void help(void)
+static void help(int status)
 {
        fprintf(stderr, "Usage: virtio_test [--help]"
                " [--no-indirect]"
@@ -337,6 +337,8 @@ static void help(void)
                " [--batch=random/N]"
                " [--reset=N]"
                "\n");
+
+       exit(status);
 }
 
 int main(int argc, char **argv)
@@ -354,14 +356,12 @@ int main(int argc, char **argv)
                case -1:
                        goto done;
                case '?':
-                       help();
-                       exit(2);
+                       help(2);
                case 'e':
                        features &= ~(1ULL << VIRTIO_RING_F_EVENT_IDX);
                        break;
                case 'h':
-                       help();
-                       goto done;
+                       help(0);
                case 'i':
                        features &= ~(1ULL << VIRTIO_RING_F_INDIRECT_DESC);
                        break;