Fix wrong return value on consumer socket creation
[lttng-tools.git] / src / bin / lttng / utils.c
CommitLineData
f3ed775e
DG
1/*
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
82a3637f
DG
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
4c462e79 19#define _GNU_SOURCE
f3ed775e 20#include <stdlib.h>
679b4943 21#include <ctype.h>
f3ed775e 22
db758600 23#include <common/error.h>
f3ed775e 24
beb8c75a 25#include "conf.h"
679b4943 26#include "utils.h"
f3ed775e 27
f3ed775e
DG
28/*
29 * get_session_name
30 *
31 * Return allocated string with the session name found in the config
32 * directory.
33 */
34char *get_session_name(void)
35{
36 char *path, *session_name = NULL;
37
38 /* Get path to config file */
58a97671 39 path = config_get_default_path();
f3ed775e
DG
40 if (path == NULL) {
41 goto error;
42 }
43
44 /* Get session name from config */
45 session_name = config_read_session_name(path);
46 if (session_name == NULL) {
58a97671 47 goto error;
f3ed775e
DG
48 }
49
3183dbb0 50 DBG2("Config file path found: %s", path);
cd80958d 51 DBG("Session name found: %s", session_name);
f3ed775e 52 return session_name;
3183dbb0
DG
53
54error:
55 return NULL;
f3ed775e 56}
679b4943
SM
57
58
59/*
60 * list_cmd_options
61 *
62 * Prints a simple list of the options available to a command. This is intended
63 * to be easily parsed for bash completion.
64 */
65void list_cmd_options(FILE *ofp, struct poptOption *options)
66{
67 int i;
68 struct poptOption *option = NULL;
69
70 for (i = 0; options[i].longName != NULL; i++) {
71 option = &options[i];
72
73 fprintf(ofp, "--%s\n", option->longName);
74
75 if (isprint(option->shortName)) {
76 fprintf(ofp, "-%c\n", option->shortName);
77 }
78 }
79}
This page took 0.049882 seconds and 5 git commands to generate.