Make symupload exit with an error code when command-line parsing fails.
This should address the issue where some Chrome builds were failing to
upload symbols due to a bad command-line flag, but there was no
indication of a problem, and no build failure, because symupload was
exiting with a success code.
BUG=1091387
R=nbilling@google.com, wuwang@google.com
Change-Id: I0d7f1a6d689ca5fd37be3abad4c5ebc97f108e50
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2231574
Reviewed-by: Nelson Billing <nbilling@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc
index f155eb9..256f73c 100644
--- a/src/tools/linux/symupload/sym_upload.cc
+++ b/src/tools/linux/symupload/sym_upload.cc
@@ -111,7 +111,7 @@
//=============================================================================
static void
SetupOptions(int argc, const char *argv[], Options *options) {
- extern int optind;
+ extern int optind, optopt;
int ch;
constexpr char flag_pattern[] = "u:v:x:p:k:t:c:i:hf?";
@@ -120,7 +120,11 @@
case 'h':
case '?':
Usage(argc, argv);
- exit(0);
+ // ch might be '?' because getopt found an error while parsing args (as
+ // opposed to finding "-?" as an arg), in which case optopt is set to
+ // the bad arg value, so return an error code if optopt is set,
+ // otherwise exit cleanly.
+ exit(optopt == 0 ? 0 : 1);
break;
case 'u':
options->proxy_user_pwd = optarg;