+static int on_recv_fd(struct lttng_kconsumerd_fd *kconsumerd_fd)
+{
+ int ret;
+
+ /* Opening the tracefile in write mode */
+ if (kconsumerd_fd->path_name != NULL) {
+ ret = open(kconsumerd_fd->path_name,
+ O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IRWXO);
+ if (ret < 0) {
+ ERR("Opening %s", kconsumerd_fd->path_name);
+ perror("open");
+ goto error;
+ }
+ kconsumerd_fd->out_fd = ret;
+ }
+
+ if (kconsumerd_fd->output == LTTNG_EVENT_MMAP) {
+ /* get the len of the mmap region */
+ ret = kernctl_get_mmap_len(kconsumerd_fd->consumerd_fd, &kconsumerd_fd->mmap_len);
+ if (ret != 0) {
+ ret = errno;
+ perror("kernctl_get_mmap_len");
+ goto error_close_fd;
+ }
+
+ kconsumerd_fd->mmap_base = mmap(NULL, kconsumerd_fd->mmap_len,
+ PROT_READ, MAP_PRIVATE, kconsumerd_fd->consumerd_fd, 0);
+ if (kconsumerd_fd->mmap_base == MAP_FAILED) {
+ perror("Error mmaping");
+ ret = -1;
+ goto error_close_fd;
+ }
+ }
+
+ /* we return 0 to let the library handle the FD internally */
+ return 0;
+
+error_close_fd:
+ {
+ int err;
+
+ err = close(kconsumerd_fd->out_fd);
+ assert(!err);
+ }
+error:
+ return ret;
+}
+