ctf: append error causes when returning errors
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder-packetized-file-stream-to-buf.c
index ac067d2b250b048231997c501e6efd8d031f4a88..64fbb183287a22c24baa2f02886b73d053eaa6dd 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #define BT_COMP_LOG_SELF_COMP self_comp
+#define BT_COMP_LOG_SELF_COMP_CLASS self_comp_class
 #define BT_LOG_OUTPUT_LEVEL log_level
 #define BT_LOG_TAG "PLUGIN/CTF/META/DECODER-DECODE-PACKET"
 #include "logging/comp-logging.h"
@@ -54,7 +55,8 @@ struct packet_header {
 static
 int decode_packet(FILE *in_fp, FILE *out_fp,
                int byte_order, bool *is_uuid_set, uint8_t *uuid,
-               bt_logging_level log_level, bt_self_component *self_comp)
+               bt_logging_level log_level, bt_self_component *self_comp,
+               bt_self_component_class *self_comp_class)
 {
        struct packet_header header;
        size_t readlen, writelen, toread;
@@ -63,7 +65,8 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
        const long offset = ftell(in_fp);
 
        if (offset < 0) {
-               BT_COMP_LOGE_ERRNO("Failed to get current metadata file position",
+               BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP,
+                       "Failed to get current metadata file position",
                        ".");
                goto error;
        }
@@ -74,7 +77,7 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
                goto end;
        }
        if (readlen < 1) {
-               BT_COMP_LOGE("Cannot decode metadata packet: offset=%ld", offset);
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode metadata packet: offset=%ld", offset);
                goto error;
        }
 
@@ -86,21 +89,21 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
        }
 
        if (header.compression_scheme) {
-               BT_COMP_LOGE("Metadata packet compression is not supported as of this version: "
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Metadata packet compression is not supported as of this version: "
                        "compression-scheme=%u, offset=%ld",
                        (unsigned int) header.compression_scheme, offset);
                goto error;
        }
 
        if (header.encryption_scheme) {
-               BT_COMP_LOGE("Metadata packet encryption is not supported as of this version: "
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Metadata packet encryption is not supported as of this version: "
                        "encryption-scheme=%u, offset=%ld",
                        (unsigned int) header.encryption_scheme, offset);
                goto error;
        }
 
        if (header.checksum || header.checksum_scheme) {
-               BT_COMP_LOGE("Metadata packet checksum verification is not supported as of this version: "
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Metadata packet checksum verification is not supported as of this version: "
                        "checksum-scheme=%u, checksum=%x, offset=%ld",
                        (unsigned int) header.checksum_scheme, header.checksum,
                        offset);
@@ -109,7 +112,7 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
 
        if (!ctf_metadata_decoder_is_packet_version_valid(header.major,
                        header.minor)) {
-               BT_COMP_LOGE("Invalid metadata packet version: "
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid metadata packet version: "
                        "version=%u.%u, offset=%ld",
                        header.major, header.minor, offset);
                goto error;
@@ -121,7 +124,7 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
                        bt_uuid_copy(uuid, header.uuid);
                        *is_uuid_set = true;
                } else if (bt_uuid_compare(header.uuid, uuid)) {
-                       BT_COMP_LOGE("Metadata UUID mismatch between packets of the same stream: "
+                       _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Metadata UUID mismatch between packets of the same stream: "
                                "packet-uuid=\"" BT_UUID_FMT "\", "
                                "expected-uuid=\"" BT_UUID_FMT "\", "
                                "offset=%ld",
@@ -133,7 +136,7 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
        }
 
        if ((header.content_size / CHAR_BIT) < sizeof(header)) {
-               BT_COMP_LOGE("Bad metadata packet content size: content-size=%u, "
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Bad metadata packet content size: content-size=%u, "
                        "offset=%ld", header.content_size, offset);
                goto error;
        }
@@ -146,13 +149,13 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
                loop_read = MIN(sizeof(buf) - 1, toread);
                readlen = fread(buf, sizeof(uint8_t), loop_read, in_fp);
                if (ferror(in_fp)) {
-                       BT_COMP_LOGE("Cannot read metadata packet buffer: "
+                       _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot read metadata packet buffer: "
                                "offset=%ld, read-size=%zu",
                                ftell(in_fp), loop_read);
                        goto error;
                }
                if (readlen > loop_read) {
-                       BT_COMP_LOGE("fread returned more byte than expected: "
+                       _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("fread returned more byte than expected: "
                                "read-size-asked=%zu, read-size-returned=%zu",
                                loop_read, readlen);
                        goto error;
@@ -160,7 +163,7 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
 
                writelen = fwrite(buf, sizeof(uint8_t), readlen, out_fp);
                if (writelen < readlen || ferror(out_fp)) {
-                       BT_COMP_LOGE("Cannot write decoded metadata text to buffer: "
+                       _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot write decoded metadata text to buffer: "
                                "read-offset=%ld, write-size=%zu",
                                ftell(in_fp), readlen);
                        goto error;
@@ -194,7 +197,8 @@ BT_HIDDEN
 int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp,
                char **buf, int byte_order, bool *is_uuid_set,
                uint8_t *uuid, bt_logging_level log_level,
-               bt_self_component *self_comp)
+               bt_self_component *self_comp,
+               bt_self_component_class *self_comp_class)
 {
        FILE *out_fp;
        size_t size;
@@ -204,7 +208,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp,
 
        out_fp = bt_open_memstream(buf, &size);
        if (!out_fp) {
-               BT_COMP_LOGE("Cannot open memory stream: %s.",
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot open memory stream: %s.",
                        strerror(errno));
                goto error;
        }
@@ -215,9 +219,9 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp,
                }
 
                tret = decode_packet(fp, out_fp, byte_order, is_uuid_set,
-                       uuid, log_level, self_comp);
+                       uuid, log_level, self_comp, self_comp_class);
                if (tret) {
-                       BT_COMP_LOGE("Cannot decode packet: index=%zu",
+                       _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode packet: index=%zu",
                                packet_index);
                        goto error;
                }
@@ -228,7 +232,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp,
        /* Make sure the whole string ends with a null character */
        tret = fputc('\0', out_fp);
        if (tret == EOF) {
-               BT_COMP_LOGE_STR(
+               _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
                        "Cannot append '\\0' to the decoded metadata buffer.");
                goto error;
        }
@@ -243,7 +247,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp,
         */
        out_fp = NULL;
        if (ret < 0) {
-               BT_COMP_LOGE_ERRNO("Cannot close memory stream", ".");
+               BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP, "Cannot close memory stream", ".");
                goto error;
        }
 
This page took 0.027246 seconds and 4 git commands to generate.