projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tap-driver.sh: flush stdout after each test result
[babeltrace.git]
/
fd-cache
/
fd-cache.c
diff --git
a/fd-cache/fd-cache.c
b/fd-cache/fd-cache.c
index c0b6859bb1077a93682be38cfb8241381e2a27f6..fcd4f4c201b4bbc9620d1dfb392debd18d1661da 100644
(file)
--- a/
fd-cache/fd-cache.c
+++ b/
fd-cache/fd-cache.c
@@
-35,8
+35,8
@@
#include <unistd.h>
#include <glib.h>
#include <unistd.h>
#include <glib.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/fd-cache-internal.h>
+#include <babeltrace
2
/assert-internal.h>
+#include <babeltrace
2
/fd-cache-internal.h>
struct file_key {
uint64_t dev;
struct file_key {
uint64_t dev;
@@
-135,17
+135,22
@@
struct bt_fd_cache_handle *bt_fd_cache_get_handle(struct bt_fd_cache *fdc,
struct fd_handle_internal *fd_internal = NULL;
struct stat statbuf;
struct file_key fk;
struct fd_handle_internal *fd_internal = NULL;
struct stat statbuf;
struct file_key fk;
- int ret;
+ int ret
, fd = -1
;
ret = stat(path, &statbuf);
if (ret < 0) {
ret = stat(path, &statbuf);
if (ret < 0) {
- BT_LOGE_ERRNO("Failed to stat file", ": path=%s", path);
+ /*
+ * This is not necessarily an error as we sometimes try to open
+ * files to see if they exist. Log the error as DEBUG severity
+ * level.
+ */
+ BT_LOGD_ERRNO("Failed to stat file", ": path=%s", path);
goto end;
}
/*
* Use the device number and inode number to uniquely identify a file.
goto end;
}
/*
* Use the device number and inode number to uniquely identify a file.
- * Even if the file as the same path, it may have been replaced so we
+ * Even if the file
h
as the same path, it may have been replaced so we
* must open a new FD for it. This replacement of file is more likely
* to happen with a lttng-live source component.
*/
* must open a new FD for it. This replacement of file is more likely
* to happen with a lttng-live source component.
*/
@@
-156,7
+161,7
@@
struct bt_fd_cache_handle *bt_fd_cache_get_handle(struct bt_fd_cache *fdc,
if (!fd_internal) {
struct file_key *file_key;
if (!fd_internal) {
struct file_key *file_key;
-
int
fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY);
if (fd < 0) {
BT_LOGE_ERRNO("Failed to open file", "path=%s", path);
goto error;
if (fd < 0) {
BT_LOGE_ERRNO("Failed to open file", "path=%s", path);
goto error;
@@
-184,12
+189,22
@@
struct bt_fd_cache_handle *bt_fd_cache_get_handle(struct bt_fd_cache *fdc,
g_hash_table_insert(fdc->cache, fd_internal->key, fd_internal);
}
g_hash_table_insert(fdc->cache, fd_internal->key, fd_internal);
}
- BT_ASSERT(fd_internal->ref_count >= 0);
-
fd_internal->ref_count++;
goto end;
error:
fd_internal->ref_count++;
goto end;
error:
+ /*
+ * Close file descriptor if it was open() and we are currently on error
+ * path.
+ */
+ if (fd != -1) {
+ ret = close(fd);
+ if (ret) {
+ BT_LOGE_ERRNO("Failed to close file descriptor",
+ ": fd=%i, path=%s", fd, path);
+ }
+ }
+
fd_cache_handle_internal_destroy(fd_internal);
fd_internal = NULL;
end:
fd_cache_handle_internal_destroy(fd_internal);
fd_internal = NULL;
end:
This page took
0.040097 seconds
and
4
git commands to generate.