Mi version command: add commit version to mi version
[lttng-tools.git] / src / bin / lttng / commands / load.c
CommitLineData
8c42d845
JG
1/*
2 * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#define _GNU_SOURCE
19#include <inttypes.h>
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <assert.h>
25
26#include <common/config/config.h>
27#include "../command.h"
28
29static char *opt_input_path;
8c42d845
JG
30static int opt_force;
31static int opt_load_all;
32
11143783
DG
33static const char *session_name;
34
8c42d845
JG
35enum {
36 OPT_HELP = 1,
37 OPT_ALL,
38 OPT_FORCE,
39};
40
41static struct poptOption load_opts[] = {
42 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
43 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
44 {"all", 'a', POPT_ARG_NONE, 0, OPT_ALL, 0, 0},
8c42d845
JG
45 {"input-path", 'i', POPT_ARG_STRING, &opt_input_path, 0, 0, 0},
46 {"force", 'f', POPT_ARG_NONE, 0, OPT_FORCE, 0, 0},
47 {0, 0, 0, 0, 0, 0, 0}
48};
49
50/*
51 * usage
52 */
53static void usage(FILE *ofp)
54{
11143783 55 fprintf(ofp, "usage: lttng load [OPTIONS] [SESSION]\n");
8c42d845
JG
56 fprintf(ofp, "\n");
57 fprintf(ofp, "Options:\n");
d7c6b799
DG
58 fprintf(ofp, " -h, --help Show this help\n");
59 fprintf(ofp, " -a, --all Load all sessions (default)\n");
60 fprintf(ofp, " -i, --input-path PATH Input path of the session file(s).\n");
61 fprintf(ofp, " If a directory, load all files in it\n");
62 fprintf(ofp, " else try to load the given file.\n");
63 fprintf(ofp, " -f, --force Override existing session(s).\n");
64 fprintf(ofp, " This will destroy existing session(s)\n");
65 fprintf(ofp, " before creating new one(s).\n");
8c42d845
JG
66}
67
68/*
69 * The 'load <options>' first level command
70 */
71int cmd_load(int argc, const char **argv)
72{
73 int ret = CMD_SUCCESS;
74 int opt;
75 poptContext pc;
76
77 pc = poptGetContext(NULL, argc, argv, load_opts, 0);
78 poptReadDefaultConfig(pc, 0);
79
c7e35b03
JR
80 /* TODO: mi support */
81 if (lttng_opt_mi) {
82 ret = -LTTNG_ERR_MI_NOT_IMPLEMENTED;
83 ERR("mi option not supported");
84 goto end;
85 }
86
8c42d845
JG
87 while ((opt = poptGetNextOpt(pc)) != -1) {
88 switch (opt) {
89 case OPT_HELP:
90 usage(stdout);
91 goto end;
92 case OPT_ALL:
93 opt_load_all = 1;
94 break;
95 case OPT_FORCE:
96 opt_force = 1;
97 break;
98 default:
99 usage(stderr);
100 ret = CMD_UNDEFINED;
101 goto end;
102 }
103 }
104
11143783
DG
105 if (!opt_load_all) {
106 session_name = poptGetArg(pc);
732b768a
DG
107 if (session_name) {
108 DBG2("Loading session name: %s", session_name);
11143783 109 }
8c42d845
JG
110 }
111
ab38c13f 112 ret = config_load_session(opt_input_path, session_name, opt_force, 0);
8c42d845 113 if (ret) {
11143783
DG
114 ERR("%s", lttng_strerror(ret));
115 ret = -ret;
279d6193
DG
116 } else {
117 if (opt_load_all) {
118 MSG("All sessions have been loaded successfully");
732b768a 119 } else if (session_name) {
8e525b95
DG
120 ret = config_init((char *)session_name);
121 if (ret < 0) {
122 ret = CMD_WARNING;
123 }
279d6193 124 MSG("Session %s has been loaded successfully", session_name);
732b768a
DG
125 } else {
126 MSG("Session has been loaded successfully");
279d6193 127 }
8c42d845
JG
128 }
129end:
130 poptFreeContext(pc);
131 return ret;
132}
This page took 0.031438 seconds and 5 git commands to generate.