X Tutup
Skip to content

Commit 9c7f220

Browse files
committed
journal-remote: convert to parse_boolean_argument() and fix type confusion
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.
1 parent c347087 commit 9c7f220

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

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

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "journal-remote.h"
1515
#include "main-func.h"
1616
#include "memory-util.h"
17+
#include "parse-argument.h"
1718
#include "pretty-print.h"
1819
#include "process-util.h"
1920
#include "rlimit-util.h"
@@ -34,8 +35,8 @@ static const char* arg_listen_raw = NULL;
3435
static const char* arg_listen_http = NULL;
3536
static const char* arg_listen_https = NULL;
3637
static char** arg_files = NULL; /* Do not free this. */
37-
static int arg_compress = true;
38-
static int arg_seal = false;
38+
static bool arg_compress = true;
39+
static bool arg_seal = false;
3940
static int http_socket = -1, https_socket = -1;
4041
static char** arg_gnutls_log = NULL;
4142

@@ -965,28 +966,15 @@ static int parse_argv(int argc, char *argv[]) {
965966
break;
966967

967968
case ARG_COMPRESS:
968-
if (optarg) {
969-
r = parse_boolean(optarg);
970-
if (r < 0)
971-
return log_error_errno(r, "Failed to parse --compress= parameter.");
972-
973-
arg_compress = !!r;
974-
} else
975-
arg_compress = true;
976-
969+
r = parse_boolean_argument("--compress", optarg, &arg_compress);
970+
if (r < 0)
971+
return r;
977972
break;
978973

979974
case ARG_SEAL:
980-
if (optarg) {
981-
r = parse_boolean(optarg);
982-
if (r < 0)
983-
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
984-
"Failed to parse --seal= parameter.");
985-
986-
arg_seal = !!r;
987-
} else
988-
arg_seal = true;
989-
975+
r = parse_boolean_argument("--seal", optarg, &arg_seal);
976+
if (r < 0)
977+
return r;
990978
break;
991979

992980
case ARG_GNUTLS_LOG: {

src/journal-remote/journal-upload.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "log.h"
2323
#include "main-func.h"
2424
#include "mkdir.h"
25+
#include "parse-argument.h"
2526
#include "parse-util.h"
2627
#include "path-util.h"
2728
#include "pretty-print.h"
@@ -356,7 +357,7 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
356357

357358
u->input = fd;
358359

359-
if (arg_follow) {
360+
if (arg_follow != 0) {
360361
r = sd_event_add_io(u->events, &u->input_event,
361362
fd, EPOLLIN, dispatch_fd_input, u);
362363
if (r < 0) {
@@ -747,16 +748,10 @@ static int parse_argv(int argc, char *argv[]) {
747748
break;
748749

749750
case ARG_FOLLOW:
750-
if (optarg) {
751-
r = parse_boolean(optarg);
752-
if (r < 0)
753-
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
754-
"Failed to parse --follow= parameter.");
755-
756-
arg_follow = !!r;
757-
} else
758-
arg_follow = true;
759-
751+
r = parse_boolean_argument("--follow", optarg, NULL);
752+
if (r < 0)
753+
return r;
754+
arg_follow = r;
760755
break;
761756

762757
case ARG_SAVE_STATE:
@@ -857,7 +852,7 @@ static int run(int argc, char **argv) {
857852
r = open_journal_for_upload(&u, j,
858853
arg_cursor ?: u.last_cursor,
859854
arg_cursor ? arg_after_cursor : true,
860-
!!arg_follow);
855+
arg_follow != 0);
861856
if (r < 0)
862857
return r;
863858
}

0 commit comments

Comments
 (0)
X Tutup