]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logs-show: move strlen() handling into update_json_data() so that we can use SD_ID128...
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Jan 2023 19:34:36 +0000 (20:34 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 21 Jan 2023 00:39:09 +0000 (00:39 +0000)
src/shared/logs-show.c

index 352f389ff8da24c1588f1dbf9ba494ac201adc6c..207aef392fc304a6c006c2da67d96de6b45516af 100644 (file)
@@ -925,6 +925,12 @@ static int update_json_data(
         struct json_data *d;
         int r;
 
+        assert(name);
+        assert(value);
+
+        if (size == SIZE_MAX)
+                size = strlen(value);
+
         if (!(flags & OUTPUT_SHOW_ALL) && strlen(name) + 1 + size >= JSON_THRESHOLD)
                 r = json_variant_new_null(&v);
         else if (utf8_is_printable(value, size))
@@ -1013,7 +1019,7 @@ static int output_json(
                 const dual_timestamp *previous_ts,
                 const sd_id128_t *previous_boot_id) {
 
-        char sid[SD_ID128_STRING_MAX], usecbuf[DECIMAL_STR_MAX(usec_t)];
+        char usecbuf[DECIMAL_STR_MAX(usec_t)];
         _cleanup_(json_variant_unrefp) JsonVariant *object = NULL;
         _cleanup_free_ char *cursor = NULL;
         JsonVariant **array = NULL;
@@ -1048,22 +1054,21 @@ static int output_json(
         if (!h)
                 return log_oom();
 
-        r = update_json_data(h, flags, "__CURSOR", cursor, strlen(cursor));
+        r = update_json_data(h, flags, "__CURSOR", cursor, SIZE_MAX);
         if (r < 0)
                 goto finish;
 
         xsprintf(usecbuf, USEC_FMT, realtime);
-        r = update_json_data(h, flags, "__REALTIME_TIMESTAMP", usecbuf, strlen(usecbuf));
+        r = update_json_data(h, flags, "__REALTIME_TIMESTAMP", usecbuf, SIZE_MAX);
         if (r < 0)
                 goto finish;
 
         xsprintf(usecbuf, USEC_FMT, monotonic);
-        r = update_json_data(h, flags, "__MONOTONIC_TIMESTAMP", usecbuf, strlen(usecbuf));
+        r = update_json_data(h, flags, "__MONOTONIC_TIMESTAMP", usecbuf, SIZE_MAX);
         if (r < 0)
                 goto finish;
 
-        sd_id128_to_string(journal_boot_id, sid);
-        r = update_json_data(h, flags, "_BOOT_ID", sid, strlen(sid));
+        r = update_json_data(h, flags, "_BOOT_ID", SD_ID128_TO_STRING(journal_boot_id), SIZE_MAX);
         if (r < 0)
                 goto finish;