Fix incorrect POPT_ARG_STRING usage
[lttng-tools.git] / lttng / commands / stop.c
CommitLineData
f3ed775e
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.
f3ed775e
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"
f3ed775e
DG
31
32static char *opt_session_name;
33
34enum {
35 OPT_HELP = 1,
36};
37
cd80958d
DG
38static struct lttng_handle *handle;
39
f3ed775e
DG
40static struct poptOption long_options[] = {
41 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
42 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
43 {0, 0, 0, 0, 0, 0, 0}
44};
45
46/*
47 * usage
48 */
49static void usage(FILE *ofp)
50{
51 fprintf(ofp, "usage: lttng stop [options] [NAME]\n");
52 fprintf(ofp, "\n");
53 fprintf(ofp, "Where NAME is an optional session name. If not specified, lttng will\n");
54 fprintf(ofp, "get it from the configuration directory (.lttng).\n");
55 fprintf(ofp, "\n");
56 fprintf(ofp, " -h, --help Show this help\n");
57 fprintf(ofp, "\n");
58}
59
60/*
cd80958d 61 * Start tracing for all trace of the session.
f3ed775e
DG
62 */
63static int stop_tracing(void)
64{
65 int ret = CMD_SUCCESS;
66 char *session_name;
67
68 if (opt_session_name == NULL) {
69 session_name = get_session_name();
70 if (session_name == NULL) {
71 ret = CMD_ERROR;
72 goto error;
73 }
74 } else {
75 session_name = opt_session_name;
76 }
77
cd80958d
DG
78 handle = lttng_create_handle(session_name, NULL);
79 if (handle == NULL) {
80 ret = -1;
81 goto error;
82 }
83
84 ret = lttng_stop_tracing(handle);
f3ed775e
DG
85 if (ret < 0) {
86 goto free_name;
87 }
88
89 MSG("Tracing stopped for session %s", session_name);
90
91free_name:
b73d0b29
MD
92 if (opt_session_name == NULL) {
93 free(session_name);
94 }
cd80958d 95
f3ed775e 96error:
cd80958d
DG
97 lttng_destroy_handle(handle);
98
f3ed775e
DG
99 return ret;
100}
101
102/*
103 * cmd_stop
104 *
105 * The 'stop <options>' first level command
106 */
107int cmd_stop(int argc, const char **argv)
108{
109 int opt, ret;
110 static poptContext pc;
111
112 pc = poptGetContext(NULL, argc, argv, long_options, 0);
113 poptReadDefaultConfig(pc, 0);
114
115 while ((opt = poptGetNextOpt(pc)) != -1) {
116 switch (opt) {
117 case OPT_HELP:
118 usage(stderr);
119 ret = CMD_SUCCESS;
120 goto end;
121 default:
122 usage(stderr);
123 ret = CMD_UNDEFINED;
124 goto end;
125 }
126 }
127
128 opt_session_name = (char*) poptGetArg(pc);
129
130 ret = stop_tracing();
131
132end:
133 return ret;
134}
This page took 0.031737 seconds and 5 git commands to generate.