]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: add OUTPUT_SKIP_UNPRINTABLE to log-show
authorMichael Vogt <michael@amutable.com>
Mon, 22 Jun 2026 13:07:21 +0000 (15:07 +0200)
committerMichael Vogt <michael@amutable.com>
Tue, 23 Jun 2026 10:41:38 +0000 (12:41 +0200)
This commit adds a new OUTPUT_SKIP_UNPRINTABLE to the OutputFlags
and adds code in `update_json_data` and `json_escape` to honor it.

When set all json fields that have unprintable data will be skipped
and `null` is send instead.

src/shared/logs-show.c
src/shared/output-mode.h

index b67fbd57d55dbd14f49c3b6d9b43d21495d09f0e..513d76558e31319a9b649382f7cde8d9726f9564 100644 (file)
@@ -1039,7 +1039,8 @@ void json_escape(
         assert(f);
         assert(p);
 
-        if (!(flags & OUTPUT_SHOW_ALL) && l >= JSON_THRESHOLD)
+        if (((flags & OUTPUT_SKIP_UNPRINTABLE) && !utf8_is_printable(p, l)) ||
+            (!(flags & OUTPUT_SHOW_ALL) && l >= JSON_THRESHOLD))
                 fputs("null", f);
 
         else if (!(flags & OUTPUT_SHOW_ALL) && !utf8_is_printable(p, l)) {
@@ -1124,6 +1125,8 @@ static int update_json_data(
                 r = sd_json_variant_new_null(&v);
         else if (utf8_is_printable(value, size))
                 r = sd_json_variant_new_stringn(&v, value, size);
+        else if (flags & OUTPUT_SKIP_UNPRINTABLE)
+                r = sd_json_variant_new_null(&v);
         else
                 r = sd_json_variant_new_array_bytes(&v, value, size);
         if (r < 0)
index 15f85117575a8fa3a35fd3c5a5d7c2a0d1acef66..151bf6b4bcec2f2e2db49d8a55669babff04234d 100644 (file)
@@ -43,12 +43,13 @@ typedef enum OutputFlags {
         OUTPUT_UTC               = 1 << 6,
         OUTPUT_NO_HOSTNAME       = 1 << 7,
         OUTPUT_TRUNCATE_NEWLINE  = 1 << 8,
+        OUTPUT_SKIP_UNPRINTABLE  = 1 << 9,
 
         /* Specific to process tree output */
-        OUTPUT_KERNEL_THREADS    = 1 << 9,
-        OUTPUT_CGROUP_XATTRS     = 1 << 10,
-        OUTPUT_CGROUP_ID         = 1 << 11,
-        OUTPUT_HIDE_EXTRA        = 1 << 12,
+        OUTPUT_KERNEL_THREADS    = 1 << 10,
+        OUTPUT_CGROUP_XATTRS     = 1 << 11,
+        OUTPUT_CGROUP_ID         = 1 << 12,
+        OUTPUT_HIDE_EXTRA        = 1 << 13,
 } OutputFlags;
 
 sd_json_format_flags_t output_mode_to_json_format_flags(OutputMode m);