Commit | Line | Data |
---|---|---|
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 | ||
19 | #include <stdlib.h> | |
20 | ||
21 | #include <lttng/lttng.h> | |
22 | ||
beb8c75a | 23 | #include "conf.h" |
f3ed775e | 24 | |
f3ed775e DG |
25 | /* |
26 | * get_session_name | |
27 | * | |
28 | * Return allocated string with the session name found in the config | |
29 | * directory. | |
30 | */ | |
31 | char *get_session_name(void) | |
32 | { | |
33 | char *path, *session_name = NULL; | |
34 | ||
35 | /* Get path to config file */ | |
58a97671 | 36 | path = config_get_default_path(); |
f3ed775e DG |
37 | if (path == NULL) { |
38 | goto error; | |
39 | } | |
40 | ||
41 | /* Get session name from config */ | |
42 | session_name = config_read_session_name(path); | |
43 | if (session_name == NULL) { | |
58a97671 | 44 | goto error; |
f3ed775e DG |
45 | } |
46 | ||
f3ed775e DG |
47 | error: |
48 | return session_name; | |
49 | } | |
50 | ||
51 | /* | |
52 | * set_session_name | |
53 | * | |
54 | * Get session name and set it for the lttng control lib. | |
55 | */ | |
5440dc42 | 56 | int set_session_name(char *name) |
f3ed775e DG |
57 | { |
58 | int ret; | |
59 | char *session_name; | |
60 | ||
b73d0b29 | 61 | if (!name) { |
5440dc42 DG |
62 | session_name = get_session_name(); |
63 | if (session_name == NULL) { | |
64 | ret = -1; | |
65 | goto error; | |
66 | } | |
b73d0b29 MD |
67 | } else { |
68 | session_name = name; | |
f3ed775e DG |
69 | } |
70 | ||
71 | lttng_set_session_name(session_name); | |
b73d0b29 MD |
72 | if (!name) |
73 | free(session_name); | |
f3ed775e DG |
74 | |
75 | ret = 0; | |
76 | ||
77 | error: | |
78 | return ret; | |
79 | } |