Port: dirfd is not portable, replace it
[babeltrace.git] / lib / ctf-ir / stream.c
index cf30d09d964037749b52828cdf24b1ac17b8b558..8ba0977c13bef601458dc296b13809805b4032c3 100644 (file)
@@ -668,6 +668,7 @@ int create_stream_file(struct bt_ctf_writer *writer,
 {
        int fd;
        GString *filename = g_string_new(stream->stream_class->name->str);
+       char *file_path;
 
        BT_LOGD("Creating stream file: writer-addr=%p, stream-addr=%p, "
                "stream-name=\"%s\", stream-class-addr=%p, stream-class-name=\"%s\"",
@@ -692,21 +693,27 @@ int create_stream_file(struct bt_ctf_writer *writer,
        }
 
        g_string_append_printf(filename, "_%" PRId64, stream->id);
-       fd = openat(writer->trace_dir_fd, filename->str,
+       file_path = g_build_filename(writer->path->str, filename->str, NULL);
+       if (file_path == NULL) {
+               fd = -1;
+               goto end;
+       }
+       fd = open(file_path,
                O_RDWR | O_CREAT | O_TRUNC,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+       g_free(file_path);
        if (fd < 0) {
                BT_LOGW("Failed to open stream file for writing: %s: "
-                       "writer-trace-dir-fd=%d, filename=\"%s\", "
+                       "filename=\"%s\", "
                        "ret=%d, errno=%d", strerror(errno),
-                       writer->trace_dir_fd, filename->str, fd, errno);
+                       filename->str, fd, errno);
                goto end;
        }
 
        BT_LOGD("Created stream file for writing: "
-               "stream-addr=%p, stream-name=\"%s\", writer-trace-dir-fd=%d, "
+               "stream-addr=%p, stream-name=\"%s\", "
                "filename=\"%s\", fd=%d", stream, bt_ctf_stream_get_name(stream),
-               writer->trace_dir_fd, filename->str, fd);
+               filename->str, fd);
 
 end:
        g_string_free(filename, TRUE);
@@ -852,7 +859,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                        /* Initialize events_discarded */
                        ret = try_set_structure_field_integer(
                                stream->packet_context, "events_discarded", 0);
-                       if (ret != 1) {
+                       if (ret < 0) {
                                BT_LOGW("Cannot set `events_discarded` field in packet context: "
                                        "ret=%d, packet-context-field-addr=%p",
                                        ret, stream->packet_context);
@@ -1126,6 +1133,10 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
 
        assert(event);
 
+       if (!event->event_header) {
+               goto end;
+       }
+
        if (event->frozen) {
                BT_LOGW_STR("Cannot populate event header field: event is frozen.");
                ret = -1;
@@ -1451,9 +1462,10 @@ void reset_structure_field(struct bt_ctf_field *structure, const char *name)
        struct bt_ctf_field *member;
 
        member = bt_ctf_field_structure_get_field(structure, name);
-       assert(member);
-       (void) bt_ctf_field_reset(member);
-       bt_put(member);
+       if (member) {
+               (void) bt_ctf_field_reset(member);
+               bt_put(member);
+       }
 }
 
 int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
@@ -1568,13 +1580,15 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                        stream->pos.offset, stream->pos.packet_size);
 
                /* Write event header */
-               BT_LOGV_STR("Serializing event's header field.");
-               ret = bt_ctf_field_serialize(event->event_header,
-                       &stream->pos, native_byte_order);
-               if (ret) {
-                       BT_LOGW("Cannot serialize event's header field: "
-                               "field-addr=%p", event->event_header);
-                       goto end;
+               if (event->event_header) {
+                       BT_LOGV_STR("Serializing event's header field.");
+                       ret = bt_ctf_field_serialize(event->event_header,
+                                       &stream->pos, native_byte_order);
+                       if (ret) {
+                               BT_LOGW("Cannot serialize event's header field: "
+                                               "field-addr=%p", event->event_header);
+                               goto end;
+                       }
                }
 
                /* Write stream event context */
This page took 0.024546 seconds and 4 git commands to generate.