From e032c6fd0419a73188f7143b18625b43a8d8f7c3 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 21 Sep 2021 21:06:30 -0400 Subject: [PATCH] common: compile libfd-tracker as C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I6eed13d24dd8a306f4aa474f7d739931f0750635 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/fd-tracker/Makefile.am | 12 ++++++++---- .../fd-tracker/{fd-tracker.c => fd-tracker.cpp} | 16 +++++++++------- src/common/fd-tracker/{inode.c => inode.cpp} | 8 ++++---- .../fd-tracker/{utils-poll.c => utils-poll.cpp} | 2 +- src/common/fd-tracker/{utils.c => utils.cpp} | 12 ++++++------ 5 files changed, 28 insertions(+), 22 deletions(-) rename src/common/fd-tracker/{fd-tracker.c => fd-tracker.cpp} (98%) rename src/common/fd-tracker/{inode.c => inode.cpp} (97%) rename src/common/fd-tracker/{utils-poll.c => utils-poll.cpp} (97%) rename src/common/fd-tracker/{utils.c => utils.cpp} (94%) diff --git a/src/common/fd-tracker/Makefile.am b/src/common/fd-tracker/Makefile.am index 05ca8e84b..68e63d42b 100644 --- a/src/common/fd-tracker/Makefile.am +++ b/src/common/fd-tracker/Makefile.am @@ -2,7 +2,11 @@ noinst_LTLIBRARIES = libfd-tracker.la -libfd_tracker_la_SOURCES = fd-tracker.h fd-tracker.c \ - utils.h utils.c \ - inode.h inode.c \ - utils-poll.c +libfd_tracker_la_SOURCES = \ + fd-tracker.cpp \ + fd-tracker.h \ + inode.cpp \ + inode.h \ + utils.cpp \ + utils.h \ + utils-poll.cpp diff --git a/src/common/fd-tracker/fd-tracker.c b/src/common/fd-tracker/fd-tracker.cpp similarity index 98% rename from src/common/fd-tracker/fd-tracker.c rename to src/common/fd-tracker/fd-tracker.cpp index a9921fa84..f1058aa52 100644 --- a/src/common/fd-tracker/fd-tracker.c +++ b/src/common/fd-tracker/fd-tracker.cpp @@ -186,7 +186,7 @@ static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry) static struct unsuspendable_fd *unsuspendable_fd_create( const char *name, int fd) { - struct unsuspendable_fd *entry = zmalloc(sizeof(*entry)); + struct unsuspendable_fd *entry = (unsuspendable_fd *) zmalloc(sizeof(*entry)); if (!entry) { goto error; @@ -363,7 +363,7 @@ end: struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, unsigned int capacity) { - struct fd_tracker *tracker = zmalloc(sizeof(struct fd_tracker)); + struct fd_tracker *tracker = (fd_tracker *) zmalloc(sizeof(struct fd_tracker)); if (!tracker) { goto end; @@ -499,8 +499,10 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, struct stat fd_stat; struct open_properties properties = { .flags = flags, - .mode.is_set = !!mode, - .mode.value = mode ? *mode : 0, + .mode = { + .is_set = !!mode, + .value = mode ? *mode : 0, + } }; pthread_mutex_lock(&tracker->lock); @@ -522,7 +524,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, } } - handle = zmalloc(sizeof(*handle)); + handle = (fs_handle_tracked *) zmalloc(sizeof(*handle)); if (!handle) { goto end; } @@ -616,7 +618,7 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, unsigned int active_fds; struct unsuspendable_fd **entries; - entries = zmalloc(fd_count * sizeof(*entries)); + entries = (unsuspendable_fd **) zmalloc(fd_count * sizeof(*entries)); if (!entries) { ret = -1; goto end; @@ -715,7 +717,7 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, * Maintain a local copy of fds_in as the user's callback may modify its * contents (e.g. setting the fd(s) to -1 after close). */ - fds = malloc(sizeof(*fds) * fd_count); + fds = (int *) malloc(sizeof(*fds) * fd_count); if (!fds) { ret = -1; goto end; diff --git a/src/common/fd-tracker/inode.c b/src/common/fd-tracker/inode.cpp similarity index 97% rename from src/common/fd-tracker/inode.c rename to src/common/fd-tracker/inode.cpp index 88e392bde..404ba360b 100644 --- a/src/common/fd-tracker/inode.c +++ b/src/common/fd-tracker/inode.cpp @@ -78,7 +78,7 @@ static unsigned long lttng_inode_id_hash(const struct inode_id *id) static int lttng_inode_match(struct cds_lfht_node *node, const void *key) { - const struct inode_id *id = key; + const struct inode_id *id = (inode_id *) key; const struct lttng_inode *inode = caa_container_of( node, struct lttng_inode, registry_node); @@ -248,7 +248,7 @@ static void lttng_inode_get(struct lttng_inode *inode) struct lttng_unlinked_file_pool *lttng_unlinked_file_pool_create( const char *path) { - struct lttng_unlinked_file_pool *pool = zmalloc(sizeof(*pool)); + struct lttng_unlinked_file_pool *pool = (lttng_unlinked_file_pool *) zmalloc(sizeof(*pool)); if (!pool) { goto error; @@ -432,7 +432,7 @@ static struct lttng_inode *lttng_inode_create(const struct inode_id *id, reference_acquired = lttng_directory_handle_get(directory_handle); LTTNG_ASSERT(reference_acquired); - inode = zmalloc(sizeof(*inode)); + inode = (lttng_inode *) zmalloc(sizeof(*inode)); if (!inode) { goto end; } @@ -453,7 +453,7 @@ end: struct lttng_inode_registry *lttng_inode_registry_create(void) { - struct lttng_inode_registry *registry = zmalloc(sizeof(*registry)); + struct lttng_inode_registry *registry = (lttng_inode_registry *) zmalloc(sizeof(*registry)); if (!registry) { goto end; diff --git a/src/common/fd-tracker/utils-poll.c b/src/common/fd-tracker/utils-poll.cpp similarity index 97% rename from src/common/fd-tracker/utils-poll.c rename to src/common/fd-tracker/utils-poll.cpp index 17349a45f..4949d8160 100644 --- a/src/common/fd-tracker/utils-poll.c +++ b/src/common/fd-tracker/utils-poll.cpp @@ -20,7 +20,7 @@ struct create_args { static int open_epoll(void *data, int *out_fd) { int ret; - struct create_args *args = data; + struct create_args *args = (create_args *) data; ret = lttng_poll_create(args->events, args->size, args->flags); if (ret < 0) { diff --git a/src/common/fd-tracker/utils.c b/src/common/fd-tracker/utils.cpp similarity index 94% rename from src/common/fd-tracker/utils.c rename to src/common/fd-tracker/utils.cpp index fc307fea9..be6c65df6 100644 --- a/src/common/fd-tracker/utils.c +++ b/src/common/fd-tracker/utils.cpp @@ -73,7 +73,7 @@ static int open_directory_handle(void *_args, int *out_fds) { int ret = 0; - struct open_directory_handle_args *args = _args; + struct open_directory_handle_args *args = (open_directory_handle_args *) _args; struct lttng_directory_handle *new_handle = NULL; new_handle = args->in_handle ? @@ -123,7 +123,7 @@ static void directory_handle_destroy( struct lttng_directory_handle *handle, void *data) { - struct fd_tracker *tracker = data; + struct fd_tracker *tracker = (fd_tracker *) data; const int ret = fd_tracker_close_unsuspendable_fd( tracker, &handle->dirfd, 1, fd_close, NULL); @@ -150,10 +150,10 @@ struct lttng_directory_handle *fd_tracker_create_directory_handle_from_handle( char *handle_name = NULL; char cwd_path[LTTNG_PATH_MAX] = "working directory"; struct lttng_directory_handle *new_handle = NULL; - struct open_directory_handle_args open_args = { - .in_handle = in_handle, - .path = path, - }; + open_directory_handle_args open_args {}; + + open_args.in_handle = in_handle; + open_args.path = path; if (!path) { if (!getcwd(cwd_path, sizeof(cwd_path))) { -- 2.34.1