]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Check help and version argument early
authorHenrik Nilsson <henrik.nilsson@bytequest.se>
Wed, 31 Jul 2019 12:16:06 +0000 (14:16 +0200)
committerHenrik Nilsson <henrik.nilsson@bytequest.se>
Thu, 1 Aug 2019 08:16:37 +0000 (10:16 +0200)
Check for the help and version arguments makes sure that it's
always possible to get the version and usage even if there are
issues in other parts of the code.

shairport.c

index 21d20dfd4bf4a862056bbacdc108fa60b416c4f6..cc1a790f21fa502063daa9a1f01859cd930a636c 100644 (file)
@@ -1363,6 +1363,18 @@ void exit_function() {
 }
 
 int main(int argc, char **argv) {
+  /* Check if we are called with -V or --version parameter */
+  if (argc >= 2 && ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0))) {
+    print_version();
+    exit(EXIT_FAILURE);
+  }
+
+  /* Check if we are called with -h or --help parameter */
+  if (argc >= 2 && ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0))) {
+    usage(argv[0]);
+    exit(EXIT_FAILURE);
+  }
+
 #ifdef CONFIG_LIBDAEMON
   pid = getpid();
 #endif
@@ -1468,18 +1480,6 @@ int main(int argc, char **argv) {
 
   r64arrayinit();
 
-  /* Check if we are called with -V or --version parameter */
-  if (argc >= 2 && ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0))) {
-    print_version();
-    exit(EXIT_FAILURE);
-  }
-
-  /* Check if we are called with -h or --help parameter */
-  if (argc >= 2 && ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0))) {
-    usage(argv[0]);
-    exit(EXIT_FAILURE);
-  }
-
 #ifdef CONFIG_LIBDAEMON
 
   /* Reset signal handlers */