]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
format_json: Move conditional error logging to a separate function.
authorEero Tamminen <eero.t.tamminen@intel.com>
Fri, 15 Dec 2023 18:18:54 +0000 (19:18 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 3 Jan 2024 15:39:36 +0000 (16:39 +0100)
This reduces the amount of duplicate code being generated.

Co-authored-by: Florian Forster <octo@collectd.org>
src/utils/format_json/open_telemetry.c

index 5f0af1e50d5e6f125bfc038bd748bddfbf1d09ac..1e45f144a7432f6c2915976c994baa39aa7d94cf 100644 (file)
 
 #include <yajl/yajl_gen.h>
 
+static void log_yajl_gen_error(int line, const char *fname, int status) {
+  if (strncmp(fname, "yajl_gen_", strlen("yajl_gen_")) != 0) {
+    return;
+  }
+  ERROR("open_telemetry.c:%d: %s failed with status %d", line, fname, status);
+}
+
 #define CHECK(f)                                                               \
   do {                                                                         \
     int status = (f);                                                          \
     if (status != 0) {                                                         \
-      if (strncmp(#f, "yajl_gen_", strlen("yajl_gen_")) == 0) {                \
-        ERROR("format_json: %s failed with status %d", #f, status);            \
-      }                                                                        \
+      log_yajl_gen_error(__LINE__, #f, status);                                \
       return status;                                                           \
     }                                                                          \
   } while (0)