src.ctf.fs: make ctf_fs_file::fp a FileUP
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 5 Dec 2023 03:25:35 +0000 (03:25 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: I7c0467a20942cf107d8f10951c8a393e3da7c608
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8264
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12302
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/data-stream-file.cpp
src/plugins/ctf/fs-src/file.cpp
src/plugins/ctf/fs-src/file.hpp
src/plugins/ctf/fs-src/metadata.cpp

index d05a04a34fc4b5812e3f680d53fdcf0058b63b5f..dd725ee75ada2d8f21a67e983f67997c5ba1379f 100644 (file)
@@ -116,7 +116,7 @@ static enum ctf_msg_iter_medium_status ds_file_mmap(struct ctf_fs_ds_file *ds_fi
     BT_ASSERT(ds_file->mmap_len > 0);
 
     ds_file->mmap_addr =
-        bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp),
+        bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp.get()),
                 ds_file->mmap_offset_in_file, static_cast<int>(ds_file->logger.level()));
     if (ds_file->mmap_addr == MAP_FAILED) {
         BT_CPPLOGE_SPEC(ds_file->logger,
index d125789e6e6c9ae68424e50a76bb06e034e444eb..33399d94fbeaee99347d53fb8c12a489c2da46e2 100644 (file)
@@ -18,16 +18,6 @@ void ctf_fs_file_destroy(struct ctf_fs_file *file)
         return;
     }
 
-    if (file->fp) {
-        BT_CPPLOGD_SPEC(file->logger, "Closing file \"{}\" ({})",
-                        file->path ? file->path->str : NULL, fmt::ptr(file->fp));
-
-        if (fclose(file->fp)) {
-            BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}",
-                            file->path ? file->path->str : "NULL", strerror(errno));
-        }
-    }
-
     if (file->path) {
         g_string_free(file->path, TRUE);
     }
@@ -64,7 +54,7 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
     struct stat stat;
 
     BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path->str, mode);
-    file->fp = fopen(file->path->str, mode);
+    file->fp.reset(fopen(file->path->str, mode));
     if (!file->fp) {
         BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
                                            file->path->str, mode);
@@ -73,7 +63,7 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
 
     BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp));
 
-    if (fstat(fileno(file->fp), &stat)) {
+    if (fstat(fileno(file->fp.get()), &stat)) {
         BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
                                            file->path->str);
         goto error;
@@ -86,13 +76,6 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
 error:
     ret = -1;
 
-    if (file->fp) {
-        if (fclose(file->fp)) {
-            BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}", file->path->str,
-                            strerror(errno));
-        }
-    }
-
 end:
     return ret;
 }
index 607c1a944e28f4a207887968b9b61a914bdad2db..33fa10d882f6fb4909acb9091c59ae8cefb6231a 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <babeltrace2/babeltrace.h>
 
+#include "cpp-common/bt2c/libc-up.hpp"
 #include "cpp-common/bt2c/logging.hpp"
 
 struct ctf_fs_file_deleter
@@ -32,8 +33,7 @@ struct ctf_fs_file
     /* Owned by this */
     GString *path = nullptr;
 
-    /* Owned by this */
-    FILE *fp = nullptr;
+    bt2c::FileUP fp;
 
     off_t size = 0;
 };
index 4957bbf9b24e8ad49db40e3beb42a0402b1370cc..842b3eb749834df460e33ce74860b1d47bc3db29 100644 (file)
@@ -83,7 +83,8 @@ int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_
         goto end;
     }
 
-    ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp);
+    ret =
+        ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp.get());
     if (ret) {
         BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot update metadata decoder's content.");
         goto end;
This page took 0.026053 seconds and 4 git commands to generate.