]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: convert to parse_boolean_argument() and fix type confusion
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2021 18:47:41 +0000 (19:47 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 17 Feb 2021 20:08:50 +0000 (21:08 +0100)
We were passing a reference to 'int arg_seal' to config_parse_bool(),
which expects a 'bool *'. Luckily, this would work, because 'bool'
is smaller than 'int', so config_parse_bool() would set the least-significant
byte of arg_seal. At least I think so. But let's use consistent types ;)

Also, modernize style a bit and don't use integers in boolean context.

src/journal-remote/journal-remote-main.c
src/journal-remote/journal-upload.c

index b9e793c08cb18cce13382bc93a80297a8dac6178..355a258be16c702a76e7119dcc4ec2e09b8b5597 100644 (file)
@@ -14,6 +14,7 @@
 #include "journal-remote.h"
 #include "main-func.h"
 #include "memory-util.h"
+#include "parse-argument.h"
 #include "pretty-print.h"
 #include "process-util.h"
 #include "rlimit-util.h"
@@ -34,8 +35,8 @@ static const char* arg_listen_raw = NULL;
 static const char* arg_listen_http = NULL;
 static const char* arg_listen_https = NULL;
 static char** arg_files = NULL; /* Do not free this. */
-static int arg_compress = true;
-static int arg_seal = false;
+static bool arg_compress = true;
+static bool arg_seal = false;
 static int http_socket = -1, https_socket = -1;
 static char** arg_gnutls_log = NULL;
 
@@ -965,28 +966,15 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_COMPRESS:
-                        if (optarg) {
-                                r = parse_boolean(optarg);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to parse --compress= parameter.");
-
-                                arg_compress = !!r;
-                        } else
-                                arg_compress = true;
-
+                        r = parse_boolean_argument("--compress", optarg, &arg_compress);
+                        if (r < 0)
+                                return r;
                         break;
 
                 case ARG_SEAL:
-                        if (optarg) {
-                                r = parse_boolean(optarg);
-                                if (r < 0)
-                                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                               "Failed to parse --seal= parameter.");
-
-                                arg_seal = !!r;
-                        } else
-                                arg_seal = true;
-
+                        r = parse_boolean_argument("--seal", optarg, &arg_seal);
+                        if (r < 0)
+                                return r;
                         break;
 
                 case ARG_GNUTLS_LOG: {
index 4d6041e911ae32f6b2bc8ecfa017992a83274426..e56e336b4f7ecae14fdef81df888cb5ae53069bb 100644 (file)
@@ -22,6 +22,7 @@
 #include "log.h"
 #include "main-func.h"
 #include "mkdir.h"
+#include "parse-argument.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "pretty-print.h"
@@ -356,7 +357,7 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
 
         u->input = fd;
 
-        if (arg_follow) {
+        if (arg_follow != 0) {
                 r = sd_event_add_io(u->events, &u->input_event,
                                     fd, EPOLLIN, dispatch_fd_input, u);
                 if (r < 0) {
@@ -747,16 +748,10 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_FOLLOW:
-                        if (optarg) {
-                                r = parse_boolean(optarg);
-                                if (r < 0)
-                                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                               "Failed to parse --follow= parameter.");
-
-                                arg_follow = !!r;
-                        } else
-                                arg_follow = true;
-
+                        r = parse_boolean_argument("--follow", optarg, NULL);
+                        if (r < 0)
+                                return r;
+                        arg_follow = r;
                         break;
 
                 case ARG_SAVE_STATE:
@@ -857,7 +852,7 @@ static int run(int argc, char **argv) {
                 r = open_journal_for_upload(&u, j,
                                             arg_cursor ?: u.last_cursor,
                                             arg_cursor ? arg_after_cursor : true,
-                                            !!arg_follow);
+                                            arg_follow != 0);
                 if (r < 0)
                         return r;
         }