X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng%2Fcommands%2Fdestroy.c;fp=lttng%2Fcommands%2Fdestroy.c;h=9519403ad1c68e26a85a913e7714dd536a2f20fc;hp=0000000000000000000000000000000000000000;hb=f3ed775ef4842019b396f06095b053c3a70bc3c8;hpb=d686b40f66ea5df5ac0b9405991bbc33348b0a88 diff --git a/lttng/commands/destroy.c b/lttng/commands/destroy.c new file mode 100644 index 000000000..9519403ad --- /dev/null +++ b/lttng/commands/destroy.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2011 - David Goulet + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "cmd.h" +#include "config.h" +#include "utils.h" + +static char *opt_session_name; + +enum { + OPT_HELP = 1, +}; + +static struct poptOption long_options[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, + {0, 0, 0, 0, 0, 0, 0} +}; + +/* + * usage + */ +static void usage(FILE *ofp) +{ + fprintf(ofp, "usage: lttng destroy [options] [NAME]\n"); + fprintf(ofp, "\n"); + fprintf(ofp, "Where NAME is an optional session name. If not specified, lttng will\n"); + fprintf(ofp, "get it from the configuration directory (.lttng).\n"); + fprintf(ofp, "\n"); + fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, "\n"); +} + +/* + * destroy_session + * + * Destroy a session removing the config directory and unregistering to the + * session daemon. + */ +static int destroy_session() +{ + int ret; + char *session_name, *path; + + if (opt_session_name == NULL) { + session_name = get_session_name(); + if (session_name == NULL) { + ret = CMD_ERROR; + goto error; + } + } else { + session_name = opt_session_name; + } + + ret = lttng_destroy_session(session_name); + if (ret < 0) { + goto free_name; + } + + path = get_config_file_path(); + if (path == NULL) { + ret = CMD_FATAL; + goto free_name; + } + + if (opt_session_name == NULL) { + config_destroy(path); + MSG("Session %s destroyed at %s", session_name, path); + } else { + MSG("Session %s destroyed", session_name); + } + + free(path); + ret = CMD_SUCCESS; + +free_name: + free(session_name); +error: + return ret; +} + +/* + * cmd_destroy + * + * The 'destroy ' first level command + */ +int cmd_destroy(int argc, const char **argv) +{ + int opt, ret = CMD_SUCCESS; + static poptContext pc; + + pc = poptGetContext(NULL, argc, argv, long_options, 0); + poptReadDefaultConfig(pc, 0); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_HELP: + usage(stderr); + goto end; + default: + usage(stderr); + ret = CMD_UNDEFINED; + goto end; + } + } + + opt_session_name = (char*) poptGetArg(pc); + + ret = destroy_session(); + +end: + return ret; +}