Port: dirfd is not portable, replace it
[babeltrace.git] / lib / ctf-writer / writer.c
index c005993be3ffea9937f05f32d3880ea1fe6fc111..2978cdfb78a02affa2f7b0e32193eb44225d10cd 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "CTF-WRITER"
+#include <babeltrace/lib-logging-internal.h>
+
 #include <babeltrace/ctf-writer/clock-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/ctf-ir/field-types-internal.h>
@@ -106,6 +109,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        int ret;
        struct bt_ctf_writer *writer = NULL;
        unsigned char uuid[16];
+       char *metadata_path = NULL;
 
        if (!path) {
                goto error;
@@ -116,6 +120,8 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error;
        }
 
+       metadata_path = g_build_filename(path, "metadata", NULL);
+
        bt_object_init(writer, bt_ctf_writer_destroy);
        writer->path = g_string_new(path);
        if (!writer->path) {
@@ -133,7 +139,12 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        }
 
        /* Generate a UUID for this writer's trace */
-       uuid_generate(uuid);
+       ret = bt_uuid_generate(uuid);
+       if (ret) {
+               BT_LOGE_STR("Cannot generate UUID for CTF writer's trace.");
+               goto error_destroy;
+       }
+
        ret = bt_ctf_trace_set_uuid(writer->trace, uuid);
        if (ret) {
                goto error_destroy;
@@ -153,22 +164,21 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error_destroy;
        }
 
-       writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG);
-       if (writer->trace_dir_fd < 0) {
+       writer->metadata_fd = open(metadata_path,
+               O_WRONLY | O_CREAT | O_TRUNC,
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+       if (writer->metadata_fd < 0) {
                perror("open");
                goto error_destroy;
        }
 
-       writer->metadata_fd = openat(writer->trace_dir_fd, "metadata",
-               O_WRONLY | O_CREAT | O_TRUNC,
-               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
-
+       g_free(metadata_path);
        return writer;
 
 error_destroy:
-       unlinkat(writer->trace_dir_fd, "metadata", 0);
        BT_PUT(writer);
 error:
+       g_free(metadata_path);
        return writer;
 }
 
@@ -182,12 +192,6 @@ void bt_ctf_writer_destroy(struct bt_object *obj)
                g_string_free(writer->path, TRUE);
        }
 
-       if (writer->trace_dir_fd > 0) {
-               if (close(writer->trace_dir_fd)) {
-                       perror("close");
-               }
-       }
-
        if (writer->metadata_fd > 0) {
                if (close(writer->metadata_fd)) {
                        perror("close");
This page took 0.034123 seconds and 4 git commands to generate.