Fix: define _LGPL_SOURCE in C files
[lttng-tools.git] / src / bin / lttng-sessiond / load-session-thread.c
CommitLineData
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
18#define _GNU_SOURCE
6c1c0768 19#define _LGPL_SOURCE
ef367a93
JG
20#include <common/error.h>
21#include <common/config/config.h>
22
23#include "load-session-thread.h"
24#include "lttng-sessiond.h"
25
26/*
27 * Destroy the thread data previously created with the init function.
28 */
29void load_session_destroy_data(struct load_session_thread_data *data)
30{
31 if (!data) {
32 return;
33 }
34
35 if (data->sem_initialized) {
36 int ret;
37
38 ret = sem_destroy(&data->message_thread_ready);
39 if (ret) {
40 PERROR("sem_destroy message_thread_ready");
41 }
42 }
43}
44
45/*
46 * Initialize the thread data. This MUST be called before the thread load
47 * session is created.
48 *
49 * Return 0 on success else a negative value. Note that the destroy function
50 * can be called with no or partially initialized data.
51 */
52int load_session_init_data(struct load_session_thread_data **data)
53{
54 int ret;
eca3ba25 55 struct load_session_thread_data *_data = NULL;
ef367a93
JG
56
57 assert(data);
58
59 /*
60 * Allocate memory here since this function is called from the main thread
61 * can die *before* the end of the load session thread.
62 */
63 _data = zmalloc(sizeof(*_data));
64 if (!_data) {
65 PERROR("zmalloc load session info");
66 goto error;
67 }
68 ret = sem_init(&_data->message_thread_ready, 0, 0);
69 if (ret) {
70 PERROR("sem_init message_thread_ready");
71 goto error;
72 }
73 _data->sem_initialized = 1;
74
75 *data = _data;
76 return 0;
77
78error:
eca3ba25 79 free(_data);
ef367a93
JG
80 return -1;
81}
82
83/*
84 * This thread loads session configurations once the session daemon is
85 * ready to process client messages.
86 */
87void *thread_load_session(void *data)
88{
89 int ret;
90 struct load_session_thread_data *info = data;
91
92 DBG("[load-session-thread] Load session");
93
94 ret = sem_wait(&info->message_thread_ready);
95 if (ret) {
96 PERROR("sem_wait message_thread_ready");
97 goto end;
98 }
99
ab38c13f
DG
100 /* Override existing session and autoload also. */
101 ret = config_load_session(info->path, NULL, 1, 1);
ef367a93
JG
102 if (ret) {
103 ERR("Session load failed: %s", error_get_str(ret));
104 }
105
106end:
107 sessiond_notify_ready();
108 return NULL;
109}
This page took 0.029833 seconds and 5 git commands to generate.