Fix: mi: snapshot: missing error handling for session name
[lttng-tools.git] / src / bin / lttng-sessiond / ht-cleanup.c
CommitLineData
0b2dc8df
MD
1/*
2 * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#define _GNU_SOURCE
6c1c0768 19#define _LGPL_SOURCE
0b2dc8df
MD
20#include <assert.h>
21
22#include <common/hashtable/hashtable.h>
23#include <common/common.h>
24#include <common/utils.h>
25
26#include "lttng-sessiond.h"
8782cc74 27#include "health-sessiond.h"
9ad42ec1 28#include "testpoint.h"
0b2dc8df
MD
29
30void *thread_ht_cleanup(void *data)
31{
32 int ret, i, pollfd, err = -1;
6cd525e8 33 ssize_t size_ret;
0b2dc8df
MD
34 uint32_t revents, nb_fd;
35 struct lttng_poll_event events;
36
37 DBG("[ht-thread] startup.");
38
39 rcu_register_thread();
40 rcu_thread_online();
41
6c71277b 42 health_register(health_sessiond, HEALTH_SESSIOND_TYPE_HT_CLEANUP);
0b2dc8df 43
9ad42ec1
MD
44 if (testpoint(sessiond_thread_ht_cleanup)) {
45 goto error_testpoint;
46 }
47
0b2dc8df
MD
48 health_code_update();
49
4a15001e 50 ret = sessiond_set_ht_cleanup_thread_pollset(&events, 2);
0b2dc8df
MD
51 if (ret < 0) {
52 goto error_poll_create;
53 }
54
55 /* Add pipe to the pollset. */
56 ret = lttng_poll_add(&events, ht_cleanup_pipe[0], LPOLLIN | LPOLLERR);
57 if (ret < 0) {
58 goto error;
59 }
60
61 health_code_update();
62
63 while (1) {
4a15001e
MD
64 int handled_event;
65
0b2dc8df
MD
66 DBG3("[ht-thread] Polling on %d fds.",
67 LTTNG_POLL_GETNB(&events));
68
69 /* Inifinite blocking call, waiting for transmission */
70restart:
4a15001e 71 handled_event = 0;
0b2dc8df
MD
72 health_poll_entry();
73 ret = lttng_poll_wait(&events, -1);
74 health_poll_exit();
75 if (ret < 0) {
76 /*
77 * Restart interrupted system call.
78 */
79 if (errno == EINTR) {
80 goto restart;
81 }
82 goto error;
83 }
84
85 nb_fd = ret;
86
87 for (i = 0; i < nb_fd; i++) {
88 struct lttng_ht *ht;
89
90 health_code_update();
91
92 /* Fetch once the poll data */
93 revents = LTTNG_POLL_GETEV(&events, i);
94 pollfd = LTTNG_POLL_GETFD(&events, i);
95
4a15001e
MD
96 if (pollfd != ht_cleanup_pipe[0]) {
97 continue;
0b2dc8df 98 }
0b2dc8df
MD
99
100 if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
101 ERR("ht cleanup pipe error");
102 goto error;
103 } else if (!(revents & LPOLLIN)) {
104 /* No POLLIN and not a catched error, stop the thread. */
105 ERR("ht cleanup failed. revent: %u", revents);
106 goto error;
107 }
108
6cd525e8
MD
109 /* Get socket from dispatch thread. */
110 size_ret = lttng_read(ht_cleanup_pipe[0], &ht,
111 sizeof(ht));
112 if (size_ret < sizeof(ht)) {
0b2dc8df
MD
113 PERROR("ht cleanup notify pipe");
114 goto error;
115 }
116 health_code_update();
117 /*
118 * The whole point of this thread is to call
119 * lttng_ht_destroy from a context that is NOT:
120 * 1) a read-side RCU lock,
121 * 2) a call_rcu thread.
122 */
123 lttng_ht_destroy(ht);
124
125 health_code_update();
126 }
4a15001e
MD
127
128 /* Only check cleanup quit when no more work to do. */
129 if (handled_event) {
130 continue;
131 }
132
133 for (i = 0; i < nb_fd; i++) {
134 health_code_update();
135
136 /* Fetch once the poll data */
137 revents = LTTNG_POLL_GETEV(&events, i);
138 pollfd = LTTNG_POLL_GETFD(&events, i);
139
140 if (pollfd == ht_cleanup_pipe[0]) {
141 continue;
142 }
143
144 /* Thread quit pipe has been closed. Killing thread. */
145 ret = sessiond_check_ht_cleanup_quit(pollfd, revents);
146 if (ret) {
147 err = 0;
148 goto exit;
149 }
150 }
0b2dc8df
MD
151 }
152
153exit:
154error:
155 lttng_poll_clean(&events);
156error_poll_create:
9ad42ec1 157error_testpoint:
4a15001e 158 DBG("[ht-cleanup] Thread terminates.");
0b2dc8df
MD
159 if (err) {
160 health_error();
161 ERR("Health error occurred in %s", __func__);
162 }
8782cc74 163 health_unregister(health_sessiond);
0b2dc8df
MD
164 rcu_thread_offline();
165 rcu_unregister_thread();
166 return NULL;
167}
This page took 0.034708 seconds and 4 git commands to generate.