#define _GNU_SOURCE
#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
}
lks->fd = ret;
+ /* 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++;
/* 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++;
}
event->fd = ret;
+ /* 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);
}
lkm->fd = ret;
+ /* 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);
}
lks->fd = ret;
+ /* 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) {
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");
+ }
return 0;
/* 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;
}
+ /* Start the kernel consumer daemon */
if (kconsumerd_pid == 0) {
ret = start_kconsumerd();
if (ret < 0) {