X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Ffd-tracker%2Ffd-tracker.c;h=eddf5ada6189dedf90cae7b407f1b4bcb2a0b9f8;hb=9e3d760f2bf927be2c59d0ccb3b64e2663ae7263;hp=8af38c29c8d075bc3e2b7819228c7b563e1a1e46;hpb=52803bf0064f5811a282c4862fee88d119d42f69;p=deliverable%2Flttng-tools.git diff --git a/src/common/fd-tracker/fd-tracker.c b/src/common/fd-tracker/fd-tracker.c index 8af38c29c..eddf5ada6 100644 --- a/src/common/fd-tracker/fd-tracker.c +++ b/src/common/fd-tracker/fd-tracker.c @@ -305,9 +305,9 @@ int fs_handle_restore(struct fs_handle *handle) 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; @@ -483,10 +483,13 @@ end: 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 = { @@ -500,23 +503,26 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, if (tracker->count.suspendable.active > 0) { ret = fd_tracker_suspend_handles(tracker, 1); if (ret) { - goto error_destroy; + ERR("Suspend handled failed"); + ret = EMFILE; + goto end; } } else { /* * There are not enough active suspendable file - * descriptors to open a new fd and still accomodate the - * tracker's capacity. + * descriptors to open a new fd and still accommodate + * the tracker's capacity. */ WARN("Cannot open file system handle, too many unsuspendable file descriptors are opened (%u)", tracker->count.unsuspendable); - ret = -EMFILE; - goto error_destroy; + ret = EMFILE; + goto end; } } handle = zmalloc(sizeof(*handle)); if (!handle) { + ret = ENOMEM; goto end; } handle->tracker = tracker; @@ -524,15 +530,15 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, ret = pthread_mutex_init(&handle->lock, NULL); if (ret) { PERROR("Failed to initialize handle mutex while creating fs handle"); - free(handle); - goto error_free; + 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 = -errno; - goto error_destroy; + /* ret contains -errno on error. */ + ret = -ret; + goto error; } handle->properties = properties; @@ -540,30 +546,31 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, 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_destroy; + 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_destroy; + ret = errno; + goto error; } handle->ino = fd_stat.st_ino; fd_tracker_track(tracker, handle); - pthread_mutex_unlock(&tracker->lock); end: + pthread_mutex_unlock(&tracker->lock); + errno = ret; return handle; -error_destroy: - pthread_mutex_destroy(&handle->lock); -error_free: +error: if (handle->inode) { lttng_inode_put(handle->inode); } + pthread_mutex_destroy(&handle->lock); +error_mutex_init: free(handle); - pthread_mutex_unlock(&tracker->lock); handle = NULL; goto end; }