From 2e7e5b6856260eedb1f63f80f725da46793cee28 Mon Sep 17 00:00:00 2001 From: Henrik Nilsson Date: Wed, 31 Jul 2019 14:16:06 +0200 Subject: [PATCH 1/2] Check help and version argument early 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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/shairport.c b/shairport.c index 21d20dfd..cc1a790f 100644 --- a/shairport.c +++ b/shairport.c @@ -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 */ From 14de9e27ab863ef0381fb84d4cb269e4c1d90d79 Mon Sep 17 00:00:00 2001 From: Henrik Nilsson Date: Thu, 1 Aug 2019 09:59:17 +0200 Subject: [PATCH 2/2] Return success on version and help argument It's not a failure to print version or usage, so use return code success. --- shairport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shairport.c b/shairport.c index cc1a790f..d458516d 100644 --- a/shairport.c +++ b/shairport.c @@ -1366,13 +1366,13 @@ 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); + exit(EXIT_SUCCESS); } /* 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); + exit(EXIT_SUCCESS); } #ifdef CONFIG_LIBDAEMON