ret = open_from_properties(path,
&handle->properties);
if (ret < 0) {
+ errno = -ret;
PERROR("Failed to restore filesystem handle to %s, open() failed",
path);
- ret = -errno;
goto end;
}
fd = ret;
return ret;
}
+/*
+ * If return NULL check errno for error.
+ */
struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
const char *path, int flags, mode_t *mode)
{
- int ret;
+ int ret = 0;
struct fs_handle *handle = NULL;
struct stat fd_stat;
struct open_properties properties = {
if (tracker->count.suspendable.active > 0) {
ret = fd_tracker_suspend_handles(tracker, 1);
if (ret) {
+ ERR("Suspend handled failed");
+ ret = EMFILE;
goto end;
}
} else {
*/
WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)",
tracker->count.unsuspendable);
+ ret = EMFILE;
goto end;
}
}
handle = zmalloc(sizeof(*handle));
if (!handle) {
+ ret = ENOMEM;
goto end;
}
handle->tracker = tracker;
ret = pthread_mutex_init(&handle->lock, NULL);
if (ret) {
PERROR("Failed to initialize handle mutex while creating fs handle");
+ ret = errno;
goto error_mutex_init;
}
handle->fd = open_from_properties(path, &properties);
if (handle->fd < 0) {
- PERROR("Failed to open fs handle to %s, open() returned", path);
+ /* ret contains -errno on error. */
+ ret = -ret;
goto error;
}
handle->inode = lttng_inode_registry_get_inode(tracker->inode_registry,
handle->fd, path);
if (!handle->inode) {
+ ret = errno;
ERR("Failed to get lttng_inode corresponding to file %s",
path);
goto error;
if (fstat(handle->fd, &fd_stat)) {
PERROR("Failed to retrieve file descriptor inode while creating fs handle, fstat() returned");
+ ret = errno;
goto error;
}
handle->ino = fd_stat.st_ino;
fd_tracker_track(tracker, handle);
end:
pthread_mutex_unlock(&tracker->lock);
+ errno = ret;
return handle;
error:
if (handle->inode) {