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>
BT_ASSERT(ds_file->mmap_len > 0);
ds_file->mmap_addr =
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,
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,
- 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);
}
if (file->path) {
g_string_free(file->path, TRUE);
}
struct stat stat;
BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path->str, 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);
if (!file->fp) {
BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
file->path->str, mode);
BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp));
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;
BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
file->path->str);
goto error;
- if (file->fp) {
- if (fclose(file->fp)) {
- BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}", file->path->str,
- strerror(errno));
- }
- }
-
#include <babeltrace2/babeltrace.h>
#include <babeltrace2/babeltrace.h>
+#include "cpp-common/bt2c/libc-up.hpp"
#include "cpp-common/bt2c/logging.hpp"
struct ctf_fs_file_deleter
#include "cpp-common/bt2c/logging.hpp"
struct ctf_fs_file_deleter
/* Owned by this */
GString *path = nullptr;
/* Owned by this */
GString *path = nullptr;
- /* Owned by this */
- FILE *fp = nullptr;
- 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;
if (ret) {
BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot update metadata decoder's content.");
goto end;