| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <stdio.h> |
| 22 | |
| 23 | #include "ltt-sessiond.h" |
| 24 | #include "libkernelctl.h" |
| 25 | #include "kernel-ctl.h" |
| 26 | #include "trace.h" |
| 27 | |
| 28 | /* |
| 29 | * kernel_create_session |
| 30 | * |
| 31 | * Create a new kernel session using the command context session. |
| 32 | */ |
| 33 | int kernel_create_session(struct command_ctx *cmd_ctx, int tracer_fd) |
| 34 | { |
| 35 | int ret; |
| 36 | struct ltt_kernel_session *lks; |
| 37 | |
| 38 | /* Allocate a new kernel session */ |
| 39 | lks = malloc(sizeof(struct ltt_kernel_session)); |
| 40 | if (lks == NULL) { |
| 41 | perror("kernel session malloc"); |
| 42 | ret = -errno; |
| 43 | goto error; |
| 44 | } |
| 45 | |
| 46 | ret = kernctl_create_session(tracer_fd); |
| 47 | if (ret < 0) { |
| 48 | goto error; |
| 49 | } |
| 50 | |
| 51 | /* Assigning session fd and to the command context */ |
| 52 | lks->fd = ret; |
| 53 | cmd_ctx->session->kernel_session = lks; |
| 54 | cmd_ctx->session->kern_session_count++; |
| 55 | |
| 56 | return 0; |
| 57 | |
| 58 | error: |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * kernel_create_channel |
| 64 | * |
| 65 | * Create a kernel channel within the kernel session. |
| 66 | */ |
| 67 | int kernel_create_channel(struct command_ctx *cmd_ctx) |
| 68 | { |
| 69 | int ret; |
| 70 | struct ltt_kernel_channel *lkc; |
| 71 | struct lttng_kernel_channel *chan; |
| 72 | |
| 73 | lkc = malloc(sizeof(struct ltt_kernel_channel)); |
| 74 | chan = malloc(sizeof(struct lttng_kernel_channel)); |
| 75 | |
| 76 | if (lkc == NULL || chan == NULL) { |
| 77 | perror("kernel channel malloc"); |
| 78 | ret = -errno; |
| 79 | goto error; |
| 80 | } |
| 81 | |
| 82 | chan->overwrite = DEFAULT_KERNEL_OVERWRITE; |
| 83 | chan->subbuf_size = DEFAULT_KERNEL_SUBBUF_SIZE; |
| 84 | chan->num_subbuf = DEFAULT_KERNEL_SUBBUF_NUM; |
| 85 | chan->switch_timer_interval = DEFAULT_KERNEL_SWITCH_TIMER; |
| 86 | chan->read_timer_interval = DEFAULT_KERNEL_READ_TIMER; |
| 87 | |
| 88 | ret = kernctl_create_channel(cmd_ctx->session->kernel_session->fd, chan); |
| 89 | if (ret < 0) { |
| 90 | goto error; |
| 91 | } |
| 92 | |
| 93 | lkc->fd = ret; |
| 94 | lkc->channel = chan; |
| 95 | CDS_INIT_LIST_HEAD(&lkc->events_list.head); |
| 96 | |
| 97 | cmd_ctx->session->kernel_session->channel = lkc; |
| 98 | |
| 99 | return 0; |
| 100 | |
| 101 | error: |
| 102 | return ret; |
| 103 | } |