Check kernel version for tests
[lttng-tools.git] / src / bin / lttng / commands / set_session.c
CommitLineData
3087ef18
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.
3087ef18
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
c399183f 28#include "../command.h"
3087ef18
DG
29
30static char *opt_session_name;
31
32enum {
33 OPT_HELP = 1,
34};
35
36static struct poptOption long_options[] = {
37 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
38 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
39 {0, 0, 0, 0, 0, 0, 0}
40};
41
42/*
43 * usage
44 */
45static void usage(FILE *ofp)
46{
47 fprintf(ofp, "usage: lttng set-session NAME\n");
48 fprintf(ofp, "\n");
49 fprintf(ofp, "Options:\n");
50 fprintf(ofp, " -h, --help Show this help\n");
51 fprintf(ofp, "\n");
52}
53
54/*
55 * set_session
56 */
57static int set_session(void)
58{
59 int ret = CMD_SUCCESS;
3087ef18 60
fffd0547 61 ret = config_init(opt_session_name);
3087ef18 62 if (ret < 0) {
fffd0547 63 ERR("Unable to set session name");
3087ef18
DG
64 ret = CMD_ERROR;
65 goto error;
66 }
67
68 MSG("Session set to %s", opt_session_name);
69 ret = CMD_SUCCESS;
70
71error:
72 return ret;
73}
74
75/*
76 * cmd_set_session
77 */
78int cmd_set_session(int argc, const char **argv)
79{
80 int opt, ret = CMD_SUCCESS;
81 static poptContext pc;
82
83 pc = poptGetContext(NULL, argc, argv, long_options, 0);
84 poptReadDefaultConfig(pc, 0);
85
86 while ((opt = poptGetNextOpt(pc)) != -1) {
87 switch (opt) {
88 case OPT_HELP:
89 usage(stderr);
90 ret = CMD_SUCCESS;
91 goto end;
92 default:
93 usage(stderr);
94 ret = CMD_UNDEFINED;
95 goto end;
96 }
97 }
98
99 opt_session_name = (char *) poptGetArg(pc);
100 if (opt_session_name == NULL) {
101 ERR("Missing session name");
102 usage(stderr);
103 goto end;
104 }
105
106 ret = set_session();
107
108end:
109 return ret;
110}
This page took 0.027983 seconds and 4 git commands to generate.