Commit | Line | Data |
---|---|---|
ef367a93 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 it | |
5 | * under the terms of the GNU General Public License, version 2 only, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | */ | |
17 | ||
6c1c0768 | 18 | #define _LGPL_SOURCE |
ef367a93 | 19 | #include <common/error.h> |
f40ef1d5 | 20 | #include <common/config/session-config.h> |
ef367a93 JG |
21 | |
22 | #include "load-session-thread.h" | |
23 | #include "lttng-sessiond.h" | |
24 | ||
25 | /* | |
26 | * Destroy the thread data previously created with the init function. | |
27 | */ | |
28 | void load_session_destroy_data(struct load_session_thread_data *data) | |
29 | { | |
30 | if (!data) { | |
31 | return; | |
32 | } | |
33 | ||
34 | if (data->sem_initialized) { | |
35 | int ret; | |
36 | ||
37 | ret = sem_destroy(&data->message_thread_ready); | |
38 | if (ret) { | |
39 | PERROR("sem_destroy message_thread_ready"); | |
40 | } | |
41 | } | |
42 | } | |
43 | ||
44 | /* | |
45 | * Initialize the thread data. This MUST be called before the thread load | |
46 | * session is created. | |
47 | * | |
48 | * Return 0 on success else a negative value. Note that the destroy function | |
49 | * can be called with no or partially initialized data. | |
50 | */ | |
51 | int load_session_init_data(struct load_session_thread_data **data) | |
52 | { | |
53 | int ret; | |
eca3ba25 | 54 | struct load_session_thread_data *_data = NULL; |
ef367a93 JG |
55 | |
56 | assert(data); | |
57 | ||
58 | /* | |
59 | * Allocate memory here since this function is called from the main thread | |
60 | * can die *before* the end of the load session thread. | |
61 | */ | |
62 | _data = zmalloc(sizeof(*_data)); | |
63 | if (!_data) { | |
64 | PERROR("zmalloc load session info"); | |
65 | goto error; | |
66 | } | |
67 | ret = sem_init(&_data->message_thread_ready, 0, 0); | |
68 | if (ret) { | |
69 | PERROR("sem_init message_thread_ready"); | |
70 | goto error; | |
71 | } | |
72 | _data->sem_initialized = 1; | |
73 | ||
74 | *data = _data; | |
75 | return 0; | |
76 | ||
77 | error: | |
eca3ba25 | 78 | free(_data); |
ef367a93 JG |
79 | return -1; |
80 | } | |
81 | ||
82 | /* | |
83 | * This thread loads session configurations once the session daemon is | |
84 | * ready to process client messages. | |
85 | */ | |
86 | void *thread_load_session(void *data) | |
87 | { | |
88 | int ret; | |
89 | struct load_session_thread_data *info = data; | |
90 | ||
91 | DBG("[load-session-thread] Load session"); | |
92 | ||
93 | ret = sem_wait(&info->message_thread_ready); | |
94 | if (ret) { | |
95 | PERROR("sem_wait message_thread_ready"); | |
96 | goto end; | |
97 | } | |
98 | ||
ab38c13f | 99 | /* Override existing session and autoload also. */ |
1b08cbce | 100 | ret = config_load_session(info->path, NULL, 1, 1, NULL); |
ef367a93 JG |
101 | if (ret) { |
102 | ERR("Session load failed: %s", error_get_str(ret)); | |
103 | } | |
104 | ||
105 | end: | |
106 | sessiond_notify_ready(); | |
107 | return NULL; | |
108 | } |