Add new API call lttng_channel_set_default_attr
[lttng-tools.git] / lttng / commands / disable_channels.c
CommitLineData
26cc6b4e
DG
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
82a3637f
DG
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
26cc6b4e
DG
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#define _GNU_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
6e2d116c
DG
28#include "../cmd.h"
29#include "../conf.h"
30#include "../utils.h"
26cc6b4e
DG
31
32static char *opt_channels;
33static char *opt_kernel;
5440dc42 34static char *opt_session_name;
26cc6b4e
DG
35static int opt_pid_all;
36static int opt_userspace;
eeac7d46 37static char *opt_cmd_name;
26cc6b4e
DG
38static pid_t opt_pid;
39
40enum {
41 OPT_HELP = 1,
42 OPT_USERSPACE,
43};
44
cd80958d
DG
45static struct lttng_handle *handle;
46
26cc6b4e
DG
47static struct poptOption long_options[] = {
48 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
49 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 50 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
26cc6b4e 51 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
6caa2bcc 52 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
26cc6b4e
DG
53 {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
54 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
55 {0, 0, 0, 0, 0, 0, 0}
56};
57
58/*
59 * usage
60 */
61static void usage(FILE *ofp)
62{
63 fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
64 fprintf(ofp, "\n");
78f0bacd 65 fprintf(ofp, " -h, --help Show this help\n");
5440dc42 66 fprintf(ofp, " -s, --session Apply on session name\n");
78f0bacd
DG
67 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
68 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
69 fprintf(ofp, " --all If -u, apply on all traceable apps\n");
70 fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
26cc6b4e
DG
71 fprintf(ofp, "\n");
72}
73
74/*
cd80958d 75 * Disabling channel using the lttng API.
26cc6b4e 76 */
cd80958d 77static int disable_channels(char *session_name)
26cc6b4e
DG
78{
79 int ret = CMD_SUCCESS;
80 char *channel_name;
7d29a247 81 struct lttng_domain dom;
26cc6b4e 82
7d29a247
DG
83 if (opt_kernel) {
84 dom.type = LTTNG_DOMAIN_KERNEL;
78f0bacd
DG
85 } else if (opt_pid != 0) {
86 dom.type = LTTNG_DOMAIN_UST_PID;
87 dom.attr.pid = opt_pid;
88 DBG("PID %d set to lttng handle", opt_pid);
89 } else if (opt_userspace && opt_cmd_name == NULL) {
90 dom.type = LTTNG_DOMAIN_UST;
91 } else if (opt_userspace && opt_cmd_name != NULL) {
92 dom.type = LTTNG_DOMAIN_UST_EXEC_NAME;
93 strncpy(dom.attr.exec_name, opt_cmd_name, NAME_MAX);
94 } else {
95 ERR("Please specify a tracer (--kernel or --userspace)");
96 ret = CMD_NOT_IMPLEMENTED;
97 goto error;
7d29a247
DG
98 }
99
cd80958d
DG
100 handle = lttng_create_handle(session_name, &dom);
101 if (handle == NULL) {
102 ret = -1;
103 goto error;
104 }
105
26cc6b4e
DG
106 /* Strip channel list */
107 channel_name = strtok(opt_channels, ",");
108 while (channel_name != NULL) {
78f0bacd
DG
109 DBG("Disabling channel %s", channel_name);
110
111 ret = lttng_disable_channel(handle, channel_name);
112 if (ret < 0) {
26cc6b4e
DG
113 goto error;
114 } else {
78f0bacd
DG
115 MSG("Channel %s disabled for session %s", channel_name,
116 session_name);
26cc6b4e
DG
117 }
118
119 /* Next channel */
120 channel_name = strtok(NULL, ",");
121 }
122
123error:
cd80958d
DG
124 lttng_destroy_handle(handle);
125
26cc6b4e
DG
126 return ret;
127}
128
129/*
130 * cmd_disable_channels
131 *
132 * Disable channel to trace session
133 */
134int cmd_disable_channels(int argc, const char **argv)
135{
136 int opt, ret;
137 static poptContext pc;
cd80958d 138 char *session_name = NULL;
26cc6b4e
DG
139
140 pc = poptGetContext(NULL, argc, argv, long_options, 0);
141 poptReadDefaultConfig(pc, 0);
142
143 while ((opt = poptGetNextOpt(pc)) != -1) {
144 switch (opt) {
145 case OPT_HELP:
146 usage(stderr);
147 ret = CMD_SUCCESS;
148 goto end;
149 case OPT_USERSPACE:
150 opt_userspace = 1;
151 break;
152 default:
153 usage(stderr);
154 ret = CMD_UNDEFINED;
155 goto end;
156 }
157 }
158
159 opt_channels = (char*) poptGetArg(pc);
160 if (opt_channels == NULL) {
161 ERR("Missing channel name(s).\n");
162 usage(stderr);
163 ret = CMD_SUCCESS;
164 goto end;
165 }
166
cd80958d
DG
167 if (!opt_session_name) {
168 session_name = get_session_name();
169 if (session_name == NULL) {
170 ret = -1;
171 goto end;
172 }
173 } else {
174 session_name = opt_session_name;
175 }
176
177 ret = disable_channels(session_name);
26cc6b4e
DG
178
179end:
180 return ret;
181}
This page took 0.030486 seconds and 4 git commands to generate.