]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: several cleanups for parse_boot_descriptor()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 27 Apr 2024 08:44:49 +0000 (17:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 May 2024 00:35:24 +0000 (09:35 +0900)
- rename to parse_id_descriptor(), to make it usable for other kind of
  ID later.
- add missing assertions,
- prefix arguments for storing results with 'ret_',
- drop unnecessary 'else'.

src/journal/journalctl.c

index f634d33a975bae8987e596a1fd28e983484341c2..868808e43277d7ffc43e2113482f3467d05fc942 100644 (file)
@@ -104,15 +104,21 @@ STATIC_DESTRUCTOR_REGISTER(arg_output_fields, set_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_compiled_pattern, pattern_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
 
-static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset) {
+static int parse_id_descriptor(const char *x, sd_id128_t *ret_id, int *ret_offset) {
         sd_id128_t id = SD_ID128_NULL;
         int off = 0, r;
 
+        assert(x);
+        assert(ret_id);
+        assert(ret_offset);
+
         if (streq(x, "all")) {
-                *boot_id = SD_ID128_NULL;
-                *offset = 0;
+                *ret_id = SD_ID128_NULL;
+                *ret_offset = 0;
                 return 0;
-        } else if (strlen(x) >= SD_ID128_STRING_MAX - 1) {
+        }
+
+        if (strlen(x) >= SD_ID128_STRING_MAX - 1) {
                 char *t;
 
                 t = strndupa_safe(x, SD_ID128_STRING_MAX - 1);
@@ -134,12 +140,8 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset
                         return r;
         }
 
-        if (boot_id)
-                *boot_id = id;
-
-        if (offset)
-                *offset = off;
-
+        *ret_id = id;
+        *ret_offset = off;
         return 1;
 }
 
@@ -517,19 +519,16 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_boot_offset = 0;
 
                         if (optarg) {
-                                r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset);
+                                r = parse_id_descriptor(optarg, &arg_boot_id, &arg_boot_offset);
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to parse boot descriptor '%s'", optarg);
 
                                 arg_boot = r;
 
-                        /* Hmm, no argument? Maybe the next
-                         * word on the command line is
-                         * supposed to be the argument? Let's
-                         * see if there is one and is parsable
-                         * as a boot descriptor... */
                         } else if (optind < argc) {
-                                r = parse_boot_descriptor(argv[optind], &arg_boot_id, &arg_boot_offset);
+                                /* Hmm, no argument? Maybe the next word on the command line is supposed to be the
+                                 * argument? Let's see if there is one and is parsable as a boot descriptor... */
+                                r = parse_id_descriptor(argv[optind], &arg_boot_id, &arg_boot_offset);
                                 if (r >= 0) {
                                         arg_boot = r;
                                         optind++;