| 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 _LGPL_SOURCE |
| 19 | #include <common/error.h> |
| 20 | #include <common/config/session-config.h> |
| 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 | |
| 35 | /* |
| 36 | * Initialize the thread data. This MUST be called before the thread load |
| 37 | * session is created. |
| 38 | * |
| 39 | * Return 0 on success else a negative value. Note that the destroy function |
| 40 | * can be called with no or partially initialized data. |
| 41 | */ |
| 42 | int load_session_init_data(struct load_session_thread_data **data) |
| 43 | { |
| 44 | struct load_session_thread_data *_data = NULL; |
| 45 | |
| 46 | assert(data); |
| 47 | |
| 48 | /* |
| 49 | * Allocate memory here since this function is called from the main thread |
| 50 | * can die *before* the end of the load session thread. |
| 51 | */ |
| 52 | _data = zmalloc(sizeof(*_data)); |
| 53 | if (!_data) { |
| 54 | PERROR("zmalloc load session info"); |
| 55 | goto error; |
| 56 | } |
| 57 | |
| 58 | *data = _data; |
| 59 | return 0; |
| 60 | |
| 61 | error: |
| 62 | free(_data); |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * This thread loads session configurations once the session daemon is |
| 68 | * ready to process client messages. |
| 69 | */ |
| 70 | void *thread_load_session(void *data) |
| 71 | { |
| 72 | int ret; |
| 73 | struct load_session_thread_data *info = data; |
| 74 | |
| 75 | DBG("[load-session-thread] Load session"); |
| 76 | |
| 77 | /* Override existing session and autoload also. */ |
| 78 | ret = config_load_session(info->path, NULL, 1, 1, NULL); |
| 79 | if (ret) { |
| 80 | ERR("Session load failed: %s", error_get_str(ret)); |
| 81 | } |
| 82 | |
| 83 | sessiond_signal_parents(); |
| 84 | return NULL; |
| 85 | } |