]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-upload: drop custom option error handling
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 8 Dec 2025 09:52:11 +0000 (10:52 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 27 Feb 2026 20:05:57 +0000 (20:05 +0000)
The line to set opterr=0 was added in the initial commit in
3d090cc6f34e5970765dd1e7ee5e648a056d180d. But afaict, this never worked as
intended, because ':' must be the first char in optstring given to
getopt_long() for it to return ':' for a missing option value. Since
this wasn't set, getopt_long() would return '?', and the missing value
would be handled as an unknown option:
  $ build/systemd-journal-upload --key
  Unknown option --key.
  $ build/systemd-journal-upload --asdf
  Unknown option --asdf.

Let's just do the standard thing:
  $ build/systemd-journal-upload --key
  build/systemd-journal-upload: option '--key' requires an argument
  $ build/systemd-journal-upload --asdf
  build/systemd-journal-upload: unrecognized option '--asdf'

(cherry picked from commit c1fcc8042180b2b6e3c9acb525e730bd6d0c75d7)
(cherry picked from commit fc9d961c50becfc7b5fc94f6cbb93a889871195e)
(cherry picked from commit 6f68b40e46daeca526fc0d91ddfad9717a5f1df6)

src/journal-remote/journal-upload.c

index 74a6ffd089982818aa52dd3af4d2dc46736f8f4e..d67acd198e28d52663af029f72f839eebb531517 100644 (file)
@@ -588,8 +588,6 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        opterr = 0;
-
         while ((c = getopt_long(argc, argv, "hu:mM:D:", options, NULL)) >= 0)
                 switch (c) {
                 case 'h':
@@ -710,14 +708,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case '?':
-                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                               "Unknown option %s.",
-                                               argv[optind - 1]);
-
-                case ':':
-                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                               "Missing argument to %s.",
-                                               argv[optind - 1]);
+                        return -EINVAL;
 
                 default:
                         assert_not_reached();