Upon execlp() some anonymous file descriptors from the kernel tracer
could be dup and thus making the refcount always > 1 on the lttng kernel
tracer side.
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
#define _GNU_SOURCE
#include <errno.h>
#define _GNU_SOURCE
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
+
lks->kconsumer_fds_sent = 0;
session->kernel_session = lks;
session->kern_session_count++;
lks->kconsumer_fds_sent = 0;
session->kernel_session = lks;
session->kern_session_count++;
/* Setup the channel fd */
lkc->fd = ret;
/* Setup the channel fd */
lkc->fd = ret;
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(lkc->fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
+
/* Add channel to session */
cds_list_add(&lkc->list, &session->channel_list.head);
session->channel_count++;
/* Add channel to session */
cds_list_add(&lkc->list, &session->channel_list.head);
session->channel_count++;
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
+
/* Add event to event list */
cds_list_add(&event->list, &channel->events_list.head);
DBG("Event %s enabled (fd: %d)", ev->name, event->fd);
/* Add event to event list */
cds_list_add(&event->list, &channel->events_list.head);
DBG("Event %s enabled (fd: %d)", ev->name, event->fd);
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(lkm->fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
+
session->metadata = lkm;
DBG("Kernel metadata opened (fd: %d and path: %s)", lkm->fd, lkm->pathname);
session->metadata = lkm;
DBG("Kernel metadata opened (fd: %d and path: %s)", lkm->fd, lkm->pathname);
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
+
ret = asprintf(&lks->pathname, "%s/trace_%d",
channel->pathname, channel->stream_count);
if (ret < 0) {
ret = asprintf(&lks->pathname, "%s/trace_%d",
channel->pathname, channel->stream_count);
if (ret < 0) {
DBG("Kernel metadata stream created (fd: %d)", ret);
session->metadata_stream_fd = ret;
DBG("Kernel metadata stream created (fd: %d)", ret);
session->metadata_stream_fd = ret;
+ /* Prevent fd duplication after execlp() */
+ ret = fcntl(session->metadata_stream_fd, F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ perror("fcntl session fd");
+ }
/* Need a session for kernel command */
if (cmd_ctx->lsm->cmd_type != LTTNG_KERNEL_LIST_EVENTS &&
cmd_ctx->session->kernel_session == NULL) {
/* Need a session for kernel command */
if (cmd_ctx->lsm->cmd_type != LTTNG_KERNEL_LIST_EVENTS &&
cmd_ctx->session->kernel_session == NULL) {
ret = create_kernel_session(cmd_ctx->session);
if (ret < 0) {
ret = LTTCOMM_KERN_SESS_FAIL;
goto error;
}
ret = create_kernel_session(cmd_ctx->session);
if (ret < 0) {
ret = LTTCOMM_KERN_SESS_FAIL;
goto error;
}
+ /* Start the kernel consumer daemon */
if (kconsumerd_pid == 0) {
ret = start_kconsumerd();
if (ret < 0) {
if (kconsumerd_pid == 0) {
ret = start_kconsumerd();
if (ret < 0) {