Major changes
[lttng-tools.git] / lttng / utils.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 modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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
19#include <stdlib.h>
20
21#include <lttng/lttng.h>
22
23#include "config.h"
24
25/*
26 * get_config_file_path
27 *
28 * Return absolute path to the configuration file.
29 */
30char *get_config_file_path(void)
31{
32 char *alloc_path, *path = NULL;
33
34 /* Get path to config directory */
35 alloc_path = config_get_default_path();
36 if (alloc_path == NULL) {
37 goto error;
38 }
39
40 /* Get path to config file */
41 path = config_generate_dir_path(alloc_path);
42 if (path == NULL) {
43 goto free_alloc_path;
44 }
45
46free_alloc_path:
47 free(alloc_path);
48error:
49 return path;
50}
51
52/*
53 * get_session_name
54 *
55 * Return allocated string with the session name found in the config
56 * directory.
57 */
58char *get_session_name(void)
59{
60 char *path, *session_name = NULL;
61
62 /* Get path to config file */
63 path = get_config_file_path();
64 if (path == NULL) {
65 goto error;
66 }
67
68 /* Get session name from config */
69 session_name = config_read_session_name(path);
70 if (session_name == NULL) {
71 goto free_path;
72 }
73
74free_path:
75 free(path);
76error:
77 return session_name;
78}
79
80/*
81 * set_session_name
82 *
83 * Get session name and set it for the lttng control lib.
84 */
85int set_session_name(void)
86{
87 int ret;
88 char *session_name;
89
90 session_name = get_session_name();
91 if (session_name == NULL) {
92 ret = -1;
93 goto error;
94 }
95
96 lttng_set_session_name(session_name);
97 free(session_name);
98
99 ret = 0;
100
101error:
102 return ret;
103}
This page took 0.027497 seconds and 5 git commands to generate.