Commit | Line | Data |
---|---|---|
826d496d MD |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
fac6795d DG |
3 | * |
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; either version 2 | |
7 | * of the License, or (at your option) any later version. | |
91d76f53 | 8 | * |
fac6795d DG |
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. | |
91d76f53 | 13 | * |
fac6795d DG |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
fac6795d DG |
17 | */ |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <fcntl.h> | |
21 | #include <getopt.h> | |
22 | #include <grp.h> | |
23 | #include <limits.h> | |
24 | #include <pthread.h> | |
8c0faa1d | 25 | #include <semaphore.h> |
fac6795d DG |
26 | #include <signal.h> |
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | #include <sys/ipc.h> | |
31 | #include <sys/shm.h> | |
32 | #include <sys/socket.h> | |
33 | #include <sys/stat.h> | |
34 | #include <sys/types.h> | |
35 | #include <unistd.h> | |
36 | ||
37 | #include <urcu/list.h> /* URCU list library (-lurcu) */ | |
38 | #include <ust/ustctl.h> /* UST control lib (-lust) */ | |
5b97ec60 | 39 | #include <lttng/lttng.h> |
fac6795d DG |
40 | |
41 | #include "liblttsessiondcomm.h" | |
42 | #include "ltt-sessiond.h" | |
75462a81 | 43 | #include "lttngerr.h" |
20fe2104 | 44 | #include "kernel-ctl.h" |
9e78d6ae | 45 | #include "ust-ctl.h" |
5b74c7b1 | 46 | #include "session.h" |
91d76f53 | 47 | #include "traceable-app.h" |
fac6795d | 48 | |
5e16da05 MD |
49 | /* |
50 | * TODO: | |
51 | * teardown: signal SIGTERM handler -> write into pipe. Threads waits | |
52 | * with epoll on pipe and on other pipes/sockets for commands. Main | |
53 | * simply waits on pthread join. | |
54 | */ | |
55 | ||
75462a81 | 56 | /* Const values */ |
686204ab MD |
57 | const char default_home_dir[] = DEFAULT_HOME_DIR; |
58 | const char default_tracing_group[] = DEFAULT_TRACING_GROUP; | |
59 | const char default_ust_sock_dir[] = DEFAULT_UST_SOCK_DIR; | |
60 | const char default_global_apps_pipe[] = DEFAULT_GLOBAL_APPS_PIPE; | |
61 | ||
fac6795d | 62 | /* Variables */ |
1d4b027a DG |
63 | int opt_verbose; /* Not static for lttngerr.h */ |
64 | int opt_quiet; /* Not static for lttngerr.h */ | |
fac6795d DG |
65 | const char *progname; |
66 | const char *opt_tracing_group; | |
5b8719f5 | 67 | static int opt_sig_parent; |
fac6795d DG |
68 | static int opt_daemon; |
69 | static int is_root; /* Set to 1 if the daemon is running as root */ | |
1d4b027a DG |
70 | static pid_t ppid; /* Parent PID for --sig-parent option */ |
71 | static pid_t kconsumerd_pid; | |
fac6795d | 72 | |
d6f42150 DG |
73 | static char apps_unix_sock_path[PATH_MAX]; /* Global application Unix socket path */ |
74 | static char client_unix_sock_path[PATH_MAX]; /* Global client Unix socket path */ | |
75 | static char kconsumerd_err_unix_sock_path[PATH_MAX]; /* kconsumerd error Unix socket path */ | |
76 | static char kconsumerd_cmd_unix_sock_path[PATH_MAX]; /* kconsumerd command Unix socket path */ | |
fac6795d | 77 | |
1d4b027a | 78 | /* Sockets and FDs */ |
d6f42150 DG |
79 | static int client_sock; |
80 | static int apps_sock; | |
81 | static int kconsumerd_err_sock; | |
8c0faa1d | 82 | static int kconsumerd_cmd_sock; |
20fe2104 | 83 | static int kernel_tracer_fd; |
1d4b027a DG |
84 | |
85 | /* Pthread, Mutexes and Semaphores */ | |
8c0faa1d | 86 | static pthread_t kconsumerd_thread; |
1d4b027a DG |
87 | static pthread_t apps_thread; |
88 | static pthread_t client_thread; | |
8c0faa1d DG |
89 | static sem_t kconsumerd_sem; |
90 | ||
1d4b027a | 91 | static pthread_mutex_t kconsumerd_pid_mutex; /* Mutex to control kconsumerd pid assignation */ |
fac6795d | 92 | |
d6f42150 | 93 | /* |
1d4b027a | 94 | * free_kernel_session |
d6f42150 | 95 | * |
1d4b027a | 96 | * Free all data structure inside a kernel session and the session pointer. |
d6f42150 | 97 | */ |
1d4b027a | 98 | static void free_kernel_session(struct ltt_kernel_session *session) |
d6f42150 | 99 | { |
1d4b027a DG |
100 | struct ltt_kernel_channel *chan; |
101 | struct ltt_kernel_stream *stream; | |
102 | struct ltt_kernel_event *event; | |
d6f42150 | 103 | |
1d4b027a DG |
104 | /* Clean metadata */ |
105 | close(session->metadata_stream_fd); | |
106 | close(session->metadata->fd); | |
107 | free(session->metadata->conf); | |
108 | free(session->metadata); | |
8c0faa1d | 109 | |
1d4b027a DG |
110 | cds_list_for_each_entry(chan, &session->channel_list.head, list) { |
111 | /* Clean all event(s) */ | |
112 | cds_list_for_each_entry(event, &chan->events_list.head, list) { | |
113 | close(event->fd); | |
114 | free(event->event); | |
115 | free(event); | |
d6f42150 | 116 | } |
8c0faa1d | 117 | |
1d4b027a DG |
118 | /* Clean streams */ |
119 | cds_list_for_each_entry(stream, &chan->stream_list.head, list) { | |
120 | close(stream->fd); | |
121 | free(stream->pathname); | |
122 | free(stream); | |
123 | } | |
124 | /* Clean channel */ | |
125 | close(chan->fd); | |
126 | free(chan->channel); | |
127 | free(chan->pathname); | |
128 | free(chan); | |
d6f42150 DG |
129 | } |
130 | ||
1d4b027a DG |
131 | close(session->fd); |
132 | free(session); | |
8c0faa1d | 133 | |
1d4b027a | 134 | DBG("All kernel session data structures freed"); |
d6f42150 DG |
135 | } |
136 | ||
fac6795d | 137 | /* |
1d4b027a | 138 | * teardown_kernel_session |
fac6795d | 139 | * |
1d4b027a DG |
140 | * Complete teardown of a kernel session. This free all data structure |
141 | * related to a kernel session and update counter. | |
fac6795d | 142 | */ |
1d4b027a | 143 | static void teardown_kernel_session(struct ltt_session *session) |
fac6795d | 144 | { |
1d4b027a DG |
145 | if (session->kernel_session != NULL) { |
146 | DBG("Tearing down kernel session"); | |
147 | free_kernel_session(session->kernel_session); | |
148 | /* Extra precaution */ | |
149 | session->kernel_session = NULL; | |
150 | /* Decrement session count */ | |
151 | session->kern_session_count--; | |
fac6795d | 152 | } |
fac6795d DG |
153 | } |
154 | ||
155 | /* | |
1d4b027a | 156 | * cleanup |
fac6795d | 157 | * |
1d4b027a | 158 | * Cleanup the daemon on exit |
fac6795d | 159 | */ |
1d4b027a | 160 | static void cleanup() |
fac6795d | 161 | { |
1d4b027a DG |
162 | int ret; |
163 | char *cmd; | |
164 | struct ltt_session *sess; | |
fac6795d | 165 | |
1d4b027a | 166 | DBG("Cleaning up"); |
e07ae692 | 167 | |
1d4b027a DG |
168 | /* <fun> */ |
169 | MSG("\n%c[%d;%dm*** assert failed *** ==> %c[%dm", 27,1,31,27,0); | |
170 | MSG("%c[%d;%dmMatthew, BEET driven development works!%c[%dm",27,1,33,27,0); | |
171 | /* </fun> */ | |
fac6795d | 172 | |
1d4b027a DG |
173 | /* Stopping all threads */ |
174 | DBG("Terminating all threads"); | |
175 | pthread_cancel(client_thread); | |
176 | pthread_cancel(apps_thread); | |
177 | if (kconsumerd_pid != 0) { | |
178 | pthread_cancel(kconsumerd_thread); | |
5b8719f5 DG |
179 | } |
180 | ||
1d4b027a DG |
181 | DBG("Unlinking all unix socket"); |
182 | unlink(client_unix_sock_path); | |
183 | unlink(apps_unix_sock_path); | |
184 | unlink(kconsumerd_err_unix_sock_path); | |
fac6795d | 185 | |
1d4b027a DG |
186 | DBG("Removing %s directory", LTTNG_RUNDIR); |
187 | ret = asprintf(&cmd, "rm -rf " LTTNG_RUNDIR); | |
188 | if (ret < 0) { | |
189 | ERR("asprintf failed. Something is really wrong!"); | |
190 | } | |
5461b305 | 191 | |
1d4b027a DG |
192 | /* Remove lttng run directory */ |
193 | ret = system(cmd); | |
194 | if (ret < 0) { | |
195 | ERR("Unable to clean " LTTNG_RUNDIR); | |
196 | } | |
5461b305 | 197 | |
1d4b027a DG |
198 | DBG("Cleaning up all session"); |
199 | /* Cleanup ALL session */ | |
200 | cds_list_for_each_entry(sess, <t_session_list.head, list) { | |
201 | teardown_kernel_session(sess); | |
202 | // TODO complete session cleanup (including UST) | |
fac6795d DG |
203 | } |
204 | ||
1d4b027a | 205 | close(kernel_tracer_fd); |
fac6795d DG |
206 | } |
207 | ||
e065084a DG |
208 | /* |
209 | * send_unix_sock | |
210 | * | |
211 | * Send data on a unix socket using the liblttsessiondcomm API. | |
212 | * | |
213 | * Return lttcomm error code. | |
214 | */ | |
215 | static int send_unix_sock(int sock, void *buf, size_t len) | |
216 | { | |
217 | /* Check valid length */ | |
218 | if (len <= 0) { | |
219 | return -1; | |
220 | } | |
221 | ||
222 | return lttcomm_send_unix_sock(sock, buf, len); | |
223 | } | |
224 | ||
5461b305 DG |
225 | /* |
226 | * clean_command_ctx | |
227 | * | |
228 | * Free memory of a command context structure. | |
229 | */ | |
230 | static void clean_command_ctx(struct command_ctx *cmd_ctx) | |
231 | { | |
232 | DBG("Clean command context structure %p", cmd_ctx); | |
233 | if (cmd_ctx) { | |
234 | if (cmd_ctx->llm) { | |
235 | free(cmd_ctx->llm); | |
236 | } | |
237 | if (cmd_ctx->lsm) { | |
238 | free(cmd_ctx->lsm); | |
239 | } | |
240 | free(cmd_ctx); | |
241 | cmd_ctx = NULL; | |
242 | } | |
243 | } | |
244 | ||
fac6795d | 245 | /* |
471d1693 | 246 | * ust_connect_app |
fac6795d DG |
247 | * |
248 | * Return a socket connected to the libust communication socket | |
249 | * of the application identified by the pid. | |
379473d2 DG |
250 | * |
251 | * If the pid is not found in the traceable list, | |
252 | * return -1 to indicate error. | |
fac6795d | 253 | */ |
471d1693 | 254 | static int ust_connect_app(pid_t pid) |
fac6795d | 255 | { |
91d76f53 DG |
256 | int sock; |
257 | struct ltt_traceable_app *lta; | |
379473d2 | 258 | |
e07ae692 DG |
259 | DBG("Connect to application pid %d", pid); |
260 | ||
91d76f53 DG |
261 | lta = find_app_by_pid(pid); |
262 | if (lta == NULL) { | |
263 | /* App not found */ | |
7442b2ba | 264 | DBG("Application pid %d not found", pid); |
379473d2 DG |
265 | return -1; |
266 | } | |
fac6795d | 267 | |
91d76f53 | 268 | sock = ustctl_connect_pid(lta->pid); |
fac6795d | 269 | if (sock < 0) { |
75462a81 | 270 | ERR("Fail connecting to the PID %d\n", pid); |
fac6795d DG |
271 | } |
272 | ||
273 | return sock; | |
274 | } | |
275 | ||
276 | /* | |
277 | * notify_apps | |
278 | * | |
279 | * Notify apps by writing 42 to a named pipe using name. | |
280 | * Every applications waiting for a ltt-sessiond will be notified | |
281 | * and re-register automatically to the session daemon. | |
282 | * | |
283 | * Return open or write error value. | |
284 | */ | |
285 | static int notify_apps(const char *name) | |
286 | { | |
287 | int fd; | |
288 | int ret = -1; | |
289 | ||
e07ae692 DG |
290 | DBG("Notify the global application pipe"); |
291 | ||
fac6795d DG |
292 | /* Try opening the global pipe */ |
293 | fd = open(name, O_WRONLY); | |
294 | if (fd < 0) { | |
295 | goto error; | |
296 | } | |
297 | ||
298 | /* Notify by writing on the pipe */ | |
299 | ret = write(fd, "42", 2); | |
300 | if (ret < 0) { | |
301 | perror("write"); | |
302 | } | |
303 | ||
304 | error: | |
305 | return ret; | |
306 | } | |
307 | ||
e065084a | 308 | /* |
5461b305 | 309 | * setup_lttng_msg |
ca95a216 | 310 | * |
5461b305 DG |
311 | * Setup the outgoing data buffer for the response (llm) by allocating the |
312 | * right amount of memory and copying the original information from the lsm | |
313 | * structure. | |
ca95a216 DG |
314 | * |
315 | * Return total size of the buffer pointed by buf. | |
316 | */ | |
5461b305 | 317 | static int setup_lttng_msg(struct command_ctx *cmd_ctx, size_t size) |
ca95a216 | 318 | { |
5461b305 | 319 | int ret, buf_size, trace_name_size; |
ca95a216 | 320 | |
5461b305 DG |
321 | /* |
322 | * Check for the trace_name. If defined, it's part of the payload data of | |
323 | * the llm structure. | |
324 | */ | |
325 | trace_name_size = strlen(cmd_ctx->lsm->trace_name); | |
326 | buf_size = trace_name_size + size; | |
327 | ||
328 | cmd_ctx->llm = malloc(sizeof(struct lttcomm_lttng_msg) + buf_size); | |
329 | if (cmd_ctx->llm == NULL) { | |
ca95a216 | 330 | perror("malloc"); |
5461b305 | 331 | ret = -ENOMEM; |
ca95a216 DG |
332 | goto error; |
333 | } | |
334 | ||
5461b305 DG |
335 | /* Copy common data */ |
336 | cmd_ctx->llm->cmd_type = cmd_ctx->lsm->cmd_type; | |
337 | cmd_ctx->llm->pid = cmd_ctx->lsm->pid; | |
338 | if (!uuid_is_null(cmd_ctx->lsm->session_uuid)) { | |
339 | uuid_copy(cmd_ctx->llm->session_uuid, cmd_ctx->lsm->session_uuid); | |
340 | } | |
341 | ||
342 | cmd_ctx->llm->trace_name_offset = trace_name_size; | |
343 | cmd_ctx->llm->data_size = size; | |
344 | cmd_ctx->lttng_msg_size = sizeof(struct lttcomm_lttng_msg) + buf_size; | |
345 | ||
346 | /* Copy trace name to the llm structure. Begining of the payload. */ | |
347 | memcpy(cmd_ctx->llm->payload, cmd_ctx->lsm->trace_name, trace_name_size); | |
ca95a216 DG |
348 | |
349 | return buf_size; | |
350 | ||
351 | error: | |
352 | return ret; | |
353 | } | |
354 | ||
1d4b027a DG |
355 | /* |
356 | * thread_manage_kconsumerd | |
357 | * | |
358 | * This thread manage the kconsumerd error sent | |
359 | * back to the session daemon. | |
360 | */ | |
361 | static void *thread_manage_kconsumerd(void *data) | |
362 | { | |
363 | int sock, ret; | |
364 | enum lttcomm_return_code code; | |
365 | ||
366 | DBG("[thread] Manage kconsumerd started"); | |
367 | ||
368 | ret = lttcomm_listen_unix_sock(kconsumerd_err_sock); | |
369 | if (ret < 0) { | |
370 | goto error; | |
371 | } | |
372 | ||
373 | sock = lttcomm_accept_unix_sock(kconsumerd_err_sock); | |
374 | if (sock < 0) { | |
375 | goto error; | |
376 | } | |
377 | ||
378 | ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code)); | |
379 | if (ret <= 0) { | |
380 | goto error; | |
381 | } | |
382 | ||
383 | if (code == KCONSUMERD_COMMAND_SOCK_READY) { | |
384 | kconsumerd_cmd_sock = lttcomm_connect_unix_sock(kconsumerd_cmd_unix_sock_path); | |
385 | if (kconsumerd_cmd_sock < 0) { | |
386 | perror("kconsumerd connect"); | |
387 | goto error; | |
388 | } | |
389 | /* Signal condition to tell that the kconsumerd is ready */ | |
390 | sem_post(&kconsumerd_sem); | |
391 | DBG("Kconsumerd command socket ready"); | |
392 | } else { | |
6f61d021 | 393 | DBG("Kconsumerd error when waiting for SOCK_READY : %s", |
1d4b027a DG |
394 | lttcomm_get_readable_code(-code)); |
395 | goto error; | |
396 | } | |
397 | ||
6f61d021 DG |
398 | while (1) { |
399 | /* Wait for any kconsumerd error */ | |
400 | ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code)); | |
401 | if (ret <= 0) { | |
402 | ERR("Kconsumerd closed the command socket"); | |
403 | goto error; | |
404 | } | |
1d4b027a | 405 | |
6f61d021 DG |
406 | ERR("Kconsumerd return code : %s", lttcomm_get_readable_code(-code)); |
407 | if (code != KCONSUMERD_POLL_HUP) { | |
408 | goto error; | |
409 | } | |
410 | } | |
1d4b027a DG |
411 | |
412 | error: | |
413 | kconsumerd_pid = 0; | |
6f61d021 | 414 | DBG("Kconsumerd thread dying"); |
1d4b027a DG |
415 | return NULL; |
416 | } | |
417 | ||
418 | /* | |
419 | * thread_manage_apps | |
420 | * | |
421 | * This thread manage the application socket communication | |
422 | */ | |
423 | static void *thread_manage_apps(void *data) | |
424 | { | |
425 | int sock, ret; | |
426 | ||
427 | /* TODO: Something more elegant is needed but fine for now */ | |
428 | /* FIXME: change all types to either uint8_t, uint32_t, uint64_t | |
429 | * for 32-bit vs 64-bit compat processes. */ | |
430 | /* replicate in ust with version number */ | |
431 | struct { | |
432 | int reg; /* 1:register, 0:unregister */ | |
433 | pid_t pid; | |
434 | uid_t uid; | |
435 | } reg_msg; | |
436 | ||
437 | DBG("[thread] Manage apps started"); | |
438 | ||
439 | ret = lttcomm_listen_unix_sock(apps_sock); | |
440 | if (ret < 0) { | |
441 | goto error; | |
442 | } | |
443 | ||
444 | /* Notify all applications to register */ | |
445 | notify_apps(default_global_apps_pipe); | |
446 | ||
447 | while (1) { | |
448 | DBG("Accepting application registration"); | |
449 | /* Blocking call, waiting for transmission */ | |
450 | sock = lttcomm_accept_unix_sock(apps_sock); | |
451 | if (sock < 0) { | |
452 | goto error; | |
453 | } | |
454 | ||
455 | /* Basic recv here to handle the very simple data | |
456 | * that the libust send to register (reg_msg). | |
457 | */ | |
458 | ret = recv(sock, ®_msg, sizeof(reg_msg), 0); | |
459 | if (ret < 0) { | |
460 | perror("recv"); | |
461 | continue; | |
462 | } | |
463 | ||
464 | /* Add application to the global traceable list */ | |
465 | if (reg_msg.reg == 1) { | |
466 | /* Registering */ | |
467 | ret = register_traceable_app(reg_msg.pid, reg_msg.uid); | |
468 | if (ret < 0) { | |
469 | /* register_traceable_app only return an error with | |
470 | * ENOMEM. At this point, we better stop everything. | |
471 | */ | |
472 | goto error; | |
473 | } | |
474 | } else { | |
475 | /* Unregistering */ | |
476 | unregister_traceable_app(reg_msg.pid); | |
477 | } | |
478 | } | |
479 | ||
480 | error: | |
481 | ||
482 | return NULL; | |
483 | } | |
484 | ||
8c0faa1d | 485 | /* |
693bd40b | 486 | * spawn_kconsumerd_thread |
8c0faa1d DG |
487 | * |
488 | * Start the thread_manage_kconsumerd. This must be done after a kconsumerd | |
489 | * exec or it will fails. | |
490 | */ | |
693bd40b | 491 | static int spawn_kconsumerd_thread(void) |
8c0faa1d DG |
492 | { |
493 | int ret; | |
494 | ||
495 | /* Setup semaphore */ | |
496 | sem_init(&kconsumerd_sem, 0, 0); | |
497 | ||
1d4b027a | 498 | ret = pthread_create(&kconsumerd_thread, NULL, thread_manage_kconsumerd, (void *) NULL); |
8c0faa1d DG |
499 | if (ret != 0) { |
500 | perror("pthread_create kconsumerd"); | |
501 | goto error; | |
502 | } | |
503 | ||
693bd40b | 504 | /* Wait for the kconsumerd thread to be ready */ |
8c0faa1d DG |
505 | sem_wait(&kconsumerd_sem); |
506 | ||
507 | return 0; | |
508 | ||
509 | error: | |
510 | return ret; | |
511 | } | |
512 | ||
513 | /* | |
693bd40b | 514 | * spawn_kconsumerd |
8c0faa1d | 515 | * |
693bd40b DG |
516 | * Fork and exec a kernel consumer daemon (kconsumerd). |
517 | * | |
518 | * NOTE: It is very important to fork a kconsumerd BEFORE opening any kernel | |
519 | * file descriptor using the libkernelctl or kernel-ctl functions. So, a | |
520 | * kernel consumer MUST only be spawned before creating a kernel session. | |
8c0faa1d DG |
521 | * |
522 | * Return pid if successful else -1. | |
523 | */ | |
693bd40b | 524 | static pid_t spawn_kconsumerd(void) |
8c0faa1d DG |
525 | { |
526 | int ret; | |
527 | pid_t pid; | |
528 | ||
529 | pid = fork(); | |
530 | if (pid == 0) { | |
531 | /* | |
532 | * Exec kconsumerd. | |
533 | */ | |
534 | execlp("kconsumerd", "kconsumerd", "--daemonize", NULL); | |
535 | if (errno != 0) { | |
536 | perror("kernel start consumer exec"); | |
537 | } | |
538 | exit(EXIT_FAILURE); | |
539 | } else if (pid > 0) { | |
540 | ret = pid; | |
541 | goto error; | |
542 | } else { | |
543 | perror("kernel start consumer fork"); | |
544 | ret = -errno; | |
545 | goto error; | |
546 | } | |
547 | ||
548 | error: | |
549 | return ret; | |
550 | } | |
551 | ||
693bd40b DG |
552 | /* |
553 | * start_kconsumerd | |
554 | * | |
555 | * Spawn the kconsumerd daemon and session daemon thread. | |
556 | */ | |
557 | static int start_kconsumerd(void) | |
558 | { | |
559 | int ret; | |
560 | ||
561 | DBG("Spawning kconsumerd"); | |
562 | ||
563 | pthread_mutex_lock(&kconsumerd_pid_mutex); | |
564 | if (kconsumerd_pid == 0) { | |
565 | ret = spawn_kconsumerd(); | |
566 | if (ret < 0) { | |
567 | ERR("Spawning kconsumerd failed"); | |
568 | ret = LTTCOMM_KERN_CONSUMER_FAIL; | |
569 | pthread_mutex_unlock(&kconsumerd_pid_mutex); | |
570 | goto error; | |
571 | } | |
572 | ||
573 | /* Setting up the global kconsumerd_pid */ | |
574 | kconsumerd_pid = ret; | |
575 | } | |
576 | pthread_mutex_unlock(&kconsumerd_pid_mutex); | |
577 | ||
6f61d021 DG |
578 | DBG("Kconsumerd pid %d", ret); |
579 | ||
693bd40b DG |
580 | DBG("Spawning kconsumerd thread"); |
581 | ||
582 | ret = spawn_kconsumerd_thread(); | |
583 | if (ret < 0) { | |
584 | ERR("Fatal error spawning kconsumerd thread"); | |
585 | ret = LTTCOMM_FATAL; | |
586 | goto error; | |
587 | } | |
588 | ||
589 | return 0; | |
590 | ||
591 | error: | |
592 | return ret; | |
593 | } | |
594 | ||
8c0faa1d DG |
595 | /* |
596 | * send_kconsumerd_fds | |
597 | * | |
598 | * Send all stream fds of the kernel session to the consumer. | |
599 | */ | |
600 | static int send_kconsumerd_fds(int sock, struct ltt_kernel_session *session) | |
601 | { | |
602 | int ret, i = 0; | |
603 | /* Plus one here for the metadata fd */ | |
604 | size_t nb_fd = session->stream_count_global + 1; | |
605 | int fds[nb_fd]; | |
606 | struct ltt_kernel_stream *stream; | |
607 | struct ltt_kernel_channel *chan; | |
608 | struct lttcomm_kconsumerd_header lkh; | |
609 | struct lttcomm_kconsumerd_msg buf[nb_fd]; | |
610 | ||
611 | /* Add metadata data */ | |
612 | fds[i] = session->metadata_stream_fd; | |
613 | buf[i].fd = fds[i]; | |
614 | buf[i].state = ACTIVE_FD; | |
615 | buf[i].max_sb_size = session->metadata->conf->subbuf_size; | |
616 | strncpy(buf[i].path_name, session->metadata->pathname, PATH_MAX); | |
617 | ||
618 | cds_list_for_each_entry(chan, &session->channel_list.head, list) { | |
619 | cds_list_for_each_entry(stream, &chan->stream_list.head, list) { | |
620 | i++; | |
621 | fds[i] = stream->fd; | |
622 | buf[i].fd = stream->fd; | |
623 | buf[i].state = stream->state; | |
624 | buf[i].max_sb_size = chan->channel->subbuf_size; | |
625 | strncpy(buf[i].path_name, stream->pathname, PATH_MAX); | |
626 | } | |
627 | } | |
628 | ||
629 | /* Setup header */ | |
630 | lkh.payload_size = nb_fd * sizeof(struct lttcomm_kconsumerd_msg); | |
631 | lkh.cmd_type = LTTCOMM_ADD_STREAM; | |
632 | ||
633 | DBG("Sending kconsumerd header"); | |
1d4b027a DG |
634 | |
635 | ret = lttcomm_send_unix_sock(sock, &lkh, sizeof(struct lttcomm_kconsumerd_header)); | |
636 | if (ret < 0) { | |
637 | perror("send kconsumerd header"); | |
638 | goto error; | |
8c0faa1d DG |
639 | } |
640 | ||
1d4b027a | 641 | DBG("Sending all fds to kconsumerd"); |
8c0faa1d | 642 | |
1d4b027a DG |
643 | ret = lttcomm_send_fds_unix_sock(sock, buf, fds, nb_fd, lkh.payload_size); |
644 | if (ret < 0) { | |
645 | perror("send kconsumerd fds"); | |
646 | goto error; | |
647 | } | |
648 | ||
649 | DBG("Kconsumerd fds sent"); | |
650 | ||
651 | return 0; | |
652 | ||
653 | error: | |
654 | return ret; | |
8c0faa1d DG |
655 | } |
656 | ||
657 | /* | |
1d4b027a | 658 | * create_trace_dir |
8c0faa1d | 659 | * |
1d4b027a | 660 | * Create the trace output directory. |
8c0faa1d | 661 | */ |
1d4b027a | 662 | static int create_trace_dir(struct ltt_kernel_session *session) |
8c0faa1d | 663 | { |
1d4b027a DG |
664 | int ret; |
665 | struct ltt_kernel_channel *chan; | |
666 | ||
667 | /* Create all channel directories */ | |
668 | cds_list_for_each_entry(chan, &session->channel_list.head, list) { | |
1b6083d9 | 669 | DBG("Creating trace directory at %s", chan->pathname); |
1d4b027a DG |
670 | ret = mkdir(chan->pathname, S_IRWXU | S_IRWXG ); |
671 | if (ret < 0) { | |
672 | perror("mkdir trace path"); | |
673 | ret = -errno; | |
674 | goto error; | |
675 | } | |
8c0faa1d | 676 | } |
1d4b027a DG |
677 | |
678 | return 0; | |
679 | ||
680 | error: | |
681 | return ret; | |
8c0faa1d DG |
682 | } |
683 | ||
fac6795d DG |
684 | /* |
685 | * process_client_msg | |
686 | * | |
5461b305 DG |
687 | * Process the command requested by the lttng client within the command |
688 | * context structure. This function make sure that the return structure (llm) | |
689 | * is set and ready for transmission before returning. | |
fac6795d | 690 | * |
e065084a | 691 | * Return any error encountered or 0 for success. |
fac6795d | 692 | */ |
5461b305 | 693 | static int process_client_msg(struct command_ctx *cmd_ctx) |
fac6795d | 694 | { |
5461b305 | 695 | int ret; |
fac6795d | 696 | |
5461b305 | 697 | DBG("Processing client command %d", cmd_ctx->lsm->cmd_type); |
fac6795d | 698 | |
379473d2 | 699 | /* Check command that needs a session */ |
5461b305 | 700 | switch (cmd_ctx->lsm->cmd_type) { |
5e16da05 MD |
701 | case LTTNG_CREATE_SESSION: |
702 | case LTTNG_LIST_SESSIONS: | |
703 | case UST_LIST_APPS: | |
704 | break; | |
705 | default: | |
5461b305 DG |
706 | cmd_ctx->session = find_session_by_uuid(cmd_ctx->lsm->session_uuid); |
707 | if (cmd_ctx->session == NULL) { | |
379473d2 | 708 | ret = LTTCOMM_SELECT_SESS; |
5461b305 | 709 | goto error; |
379473d2 | 710 | } |
5e16da05 | 711 | break; |
379473d2 DG |
712 | } |
713 | ||
20fe2104 DG |
714 | /* Check command for kernel tracing */ |
715 | switch (cmd_ctx->lsm->cmd_type) { | |
716 | case KERNEL_CREATE_SESSION: | |
717 | case KERNEL_CREATE_CHANNEL: | |
8c0faa1d | 718 | case KERNEL_CREATE_STREAM: |
aaf26714 DG |
719 | case KERNEL_DISABLE_EVENT: |
720 | case KERNEL_ENABLE_EVENT: | |
721 | case KERNEL_OPEN_METADATA: | |
722 | case KERNEL_START_TRACE: | |
723 | case KERNEL_STOP_TRACE: | |
724 | /* TODO: reconnect to kernel tracer to check if | |
725 | * it's loadded */ | |
20fe2104 DG |
726 | if (kernel_tracer_fd == 0) { |
727 | ret = LTTCOMM_KERN_NA; | |
728 | goto error; | |
729 | } | |
730 | break; | |
731 | } | |
732 | ||
471d1693 | 733 | /* Connect to ust apps if available pid */ |
5461b305 | 734 | if (cmd_ctx->lsm->pid > 0) { |
471d1693 | 735 | /* Connect to app using ustctl API */ |
5461b305 DG |
736 | cmd_ctx->ust_sock = ust_connect_app(cmd_ctx->lsm->pid); |
737 | if (cmd_ctx->ust_sock < 0) { | |
471d1693 | 738 | ret = LTTCOMM_NO_TRACEABLE; |
5461b305 | 739 | goto error; |
471d1693 DG |
740 | } |
741 | } | |
742 | ||
fac6795d | 743 | /* Process by command type */ |
5461b305 | 744 | switch (cmd_ctx->lsm->cmd_type) { |
20fe2104 DG |
745 | case KERNEL_CREATE_SESSION: |
746 | { | |
747 | ret = setup_lttng_msg(cmd_ctx, 0); | |
748 | if (ret < 0) { | |
749 | goto setup_error; | |
750 | } | |
751 | ||
693bd40b | 752 | ret = start_kconsumerd(); |
8c0faa1d | 753 | if (ret < 0) { |
8c0faa1d DG |
754 | goto error; |
755 | } | |
756 | ||
20fe2104 DG |
757 | DBG("Creating kernel session"); |
758 | ||
8c0faa1d | 759 | ret = kernel_create_session(cmd_ctx->session, kernel_tracer_fd); |
20fe2104 DG |
760 | if (ret < 0) { |
761 | ret = LTTCOMM_KERN_SESS_FAIL; | |
762 | goto error; | |
763 | } | |
764 | ||
765 | ret = LTTCOMM_OK; | |
766 | break; | |
767 | } | |
768 | case KERNEL_CREATE_CHANNEL: | |
769 | { | |
770 | ret = setup_lttng_msg(cmd_ctx, 0); | |
771 | if (ret < 0) { | |
772 | goto setup_error; | |
773 | } | |
774 | ||
8c0faa1d DG |
775 | DBG("Creating kernel channel"); |
776 | ||
777 | ret = kernel_create_channel(cmd_ctx->session->kernel_session); | |
20fe2104 | 778 | |
20fe2104 DG |
779 | if (ret < 0) { |
780 | ret = LTTCOMM_KERN_CHAN_FAIL; | |
781 | goto error; | |
782 | } | |
783 | ||
784 | ret = LTTCOMM_OK; | |
785 | break; | |
786 | } | |
894be886 DG |
787 | case KERNEL_ENABLE_EVENT: |
788 | { | |
789 | /* Setup lttng message with no payload */ | |
790 | ret = setup_lttng_msg(cmd_ctx, 0); | |
791 | if (ret < 0) { | |
792 | goto setup_error; | |
793 | } | |
794 | ||
795 | DBG("Enabling kernel event %s", cmd_ctx->lsm->u.event.event_name); | |
796 | ||
8c0faa1d | 797 | ret = kernel_enable_event(cmd_ctx->session->kernel_session, cmd_ctx->lsm->u.event.event_name); |
f34daff7 DG |
798 | if (ret < 0) { |
799 | ret = LTTCOMM_KERN_ENABLE_FAIL; | |
800 | goto error; | |
801 | } | |
802 | ||
894be886 DG |
803 | ret = LTTCOMM_OK; |
804 | break; | |
805 | } | |
aaf26714 DG |
806 | case KERNEL_OPEN_METADATA: |
807 | { | |
808 | /* Setup lttng message with no payload */ | |
809 | ret = setup_lttng_msg(cmd_ctx, 0); | |
810 | if (ret < 0) { | |
811 | goto setup_error; | |
812 | } | |
813 | ||
814 | DBG("Open kernel metadata"); | |
815 | ||
816 | ret = kernel_open_metadata(cmd_ctx->session->kernel_session); | |
817 | if (ret < 0) { | |
818 | ret = LTTCOMM_KERN_META_FAIL; | |
819 | goto error; | |
820 | } | |
821 | ||
822 | ret = LTTCOMM_OK; | |
823 | break; | |
824 | } | |
8c0faa1d DG |
825 | case KERNEL_CREATE_STREAM: |
826 | { | |
827 | struct ltt_kernel_channel *chan; | |
828 | /* Setup lttng message with no payload */ | |
829 | ret = setup_lttng_msg(cmd_ctx, 0); | |
830 | if (ret < 0) { | |
831 | goto setup_error; | |
832 | } | |
833 | ||
834 | DBG("Creating kernel stream"); | |
835 | ||
836 | ret = kernel_create_metadata_stream(cmd_ctx->session->kernel_session); | |
837 | if (ret < 0) { | |
838 | ERR("Kernel create metadata stream failed"); | |
839 | ret = LTTCOMM_KERN_STREAM_FAIL; | |
840 | goto error; | |
841 | } | |
842 | ||
843 | /* For each channel */ | |
844 | cds_list_for_each_entry(chan, &cmd_ctx->session->kernel_session->channel_list.head, list) { | |
845 | ret = kernel_create_channel_stream(chan); | |
846 | if (ret < 0) { | |
847 | ERR("Kernel create channel stream failed"); | |
848 | ret = LTTCOMM_KERN_STREAM_FAIL; | |
849 | goto error; | |
850 | } | |
851 | /* Update the stream global counter */ | |
852 | cmd_ctx->session->kernel_session->stream_count_global += ret; | |
853 | } | |
854 | ||
855 | ret = LTTCOMM_OK; | |
856 | break; | |
857 | } | |
858 | case KERNEL_START_TRACE: | |
859 | { | |
860 | /* Setup lttng message with no payload */ | |
861 | ret = setup_lttng_msg(cmd_ctx, 0); | |
862 | if (ret < 0) { | |
863 | goto setup_error; | |
864 | } | |
865 | ||
866 | DBG("Start kernel tracing"); | |
867 | ||
868 | ret = create_trace_dir(cmd_ctx->session->kernel_session); | |
869 | if (ret < 0) { | |
870 | if (ret == -EEXIST) { | |
871 | ret = LTTCOMM_KERN_DIR_EXIST; | |
872 | } else { | |
873 | ret = LTTCOMM_KERN_DIR_FAIL; | |
874 | goto error; | |
875 | } | |
876 | } | |
877 | ||
878 | ret = kernel_start_session(cmd_ctx->session->kernel_session); | |
879 | if (ret < 0) { | |
880 | ERR("Kernel start session failed"); | |
881 | ret = LTTCOMM_KERN_START_FAIL; | |
882 | goto error; | |
883 | } | |
884 | ||
885 | ret = send_kconsumerd_fds(kconsumerd_cmd_sock, cmd_ctx->session->kernel_session); | |
886 | if (ret < 0) { | |
887 | ERR("Send kconsumerd fds failed"); | |
888 | ret = LTTCOMM_KERN_CONSUMER_FAIL; | |
889 | goto error; | |
890 | } | |
891 | ||
892 | ret = LTTCOMM_OK; | |
893 | break; | |
894 | } | |
895 | case KERNEL_STOP_TRACE: | |
896 | { | |
897 | /* Setup lttng message with no payload */ | |
898 | ret = setup_lttng_msg(cmd_ctx, 0); | |
899 | if (ret < 0) { | |
900 | goto setup_error; | |
901 | } | |
902 | ||
84291629 DG |
903 | if (cmd_ctx->session->kernel_session == NULL) { |
904 | ret = LTTCOMM_KERN_NO_SESSION; | |
905 | goto error; | |
906 | } | |
907 | ||
8c0faa1d DG |
908 | DBG("Stop kernel tracing"); |
909 | ||
910 | ret = kernel_stop_session(cmd_ctx->session->kernel_session); | |
911 | if (ret < 0) { | |
912 | ERR("Kernel stop session failed"); | |
913 | ret = LTTCOMM_KERN_STOP_FAIL; | |
914 | goto error; | |
915 | } | |
916 | ||
917 | /* Clean kernel session teardown */ | |
918 | teardown_kernel_session(cmd_ctx->session); | |
919 | ||
920 | ret = LTTCOMM_OK; | |
921 | break; | |
922 | } | |
5e16da05 MD |
923 | case LTTNG_CREATE_SESSION: |
924 | { | |
5461b305 DG |
925 | /* Setup lttng message with no payload */ |
926 | ret = setup_lttng_msg(cmd_ctx, 0); | |
927 | if (ret < 0) { | |
928 | goto setup_error; | |
929 | } | |
930 | ||
931 | ret = create_session(cmd_ctx->lsm->session_name, &cmd_ctx->llm->session_uuid); | |
5e16da05 MD |
932 | if (ret < 0) { |
933 | if (ret == -1) { | |
934 | ret = LTTCOMM_EXIST_SESS; | |
935 | } else { | |
aaf97519 | 936 | ret = LTTCOMM_FATAL; |
aaf97519 | 937 | } |
5461b305 | 938 | goto error; |
8028d920 | 939 | } |
1657e9bb | 940 | |
5461b305 | 941 | ret = LTTCOMM_OK; |
5e16da05 MD |
942 | break; |
943 | } | |
944 | case LTTNG_DESTROY_SESSION: | |
945 | { | |
5461b305 DG |
946 | /* Setup lttng message with no payload */ |
947 | ret = setup_lttng_msg(cmd_ctx, 0); | |
948 | if (ret < 0) { | |
949 | goto setup_error; | |
950 | } | |
951 | ||
952 | ret = destroy_session(&cmd_ctx->lsm->session_uuid); | |
5e16da05 MD |
953 | if (ret < 0) { |
954 | ret = LTTCOMM_NO_SESS; | |
5461b305 | 955 | goto error; |
5e16da05 | 956 | } |
1657e9bb | 957 | |
5461b305 DG |
958 | ret = LTTCOMM_OK; |
959 | break; | |
5e16da05 MD |
960 | } |
961 | case LTTNG_LIST_TRACES: | |
962 | { | |
5461b305 | 963 | unsigned int trace_count; |
1657e9bb | 964 | |
5461b305 | 965 | trace_count = get_trace_count_per_session(cmd_ctx->session); |
5e16da05 MD |
966 | if (trace_count == 0) { |
967 | ret = LTTCOMM_NO_TRACE; | |
5461b305 | 968 | goto error; |
1657e9bb | 969 | } |
df0da139 | 970 | |
5461b305 DG |
971 | ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_trace) * trace_count); |
972 | if (ret < 0) { | |
973 | goto setup_error; | |
df0da139 | 974 | } |
ca95a216 | 975 | |
5461b305 DG |
976 | get_traces_per_session(cmd_ctx->session, |
977 | (struct lttng_trace *)(cmd_ctx->llm->payload)); | |
978 | ||
979 | ret = LTTCOMM_OK; | |
5e16da05 MD |
980 | break; |
981 | } | |
982 | case UST_CREATE_TRACE: | |
983 | { | |
5461b305 DG |
984 | /* Setup lttng message with no payload */ |
985 | ret = setup_lttng_msg(cmd_ctx, 0); | |
5e16da05 | 986 | if (ret < 0) { |
5461b305 | 987 | goto setup_error; |
fac6795d | 988 | } |
ce3d728c | 989 | |
5461b305 DG |
990 | ret = ust_create_trace(cmd_ctx); |
991 | if (ret < 0) { | |
992 | goto setup_error; | |
993 | } | |
994 | break; | |
5e16da05 MD |
995 | } |
996 | case UST_LIST_APPS: | |
997 | { | |
5461b305 DG |
998 | unsigned int app_count; |
999 | ||
1000 | app_count = get_app_count(); | |
1001 | DBG("Traceable application count : %d", app_count); | |
5e16da05 MD |
1002 | if (app_count == 0) { |
1003 | ret = LTTCOMM_NO_APPS; | |
5461b305 | 1004 | goto error; |
ce3d728c | 1005 | } |
520ff687 | 1006 | |
5461b305 DG |
1007 | ret = setup_lttng_msg(cmd_ctx, sizeof(pid_t) * app_count); |
1008 | if (ret < 0) { | |
1009 | goto setup_error; | |
520ff687 | 1010 | } |
57167058 | 1011 | |
5461b305 | 1012 | get_app_list_pids((pid_t *)(cmd_ctx->llm->payload)); |
5e16da05 | 1013 | |
5461b305 | 1014 | ret = LTTCOMM_OK; |
5e16da05 MD |
1015 | break; |
1016 | } | |
1017 | case UST_START_TRACE: | |
1018 | { | |
5461b305 DG |
1019 | /* Setup lttng message with no payload */ |
1020 | ret = setup_lttng_msg(cmd_ctx, 0); | |
1021 | if (ret < 0) { | |
1022 | goto setup_error; | |
1023 | } | |
ca95a216 | 1024 | |
5461b305 DG |
1025 | ret = ust_start_trace(cmd_ctx); |
1026 | if (ret < 0) { | |
1027 | goto setup_error; | |
1028 | } | |
1029 | break; | |
5e16da05 MD |
1030 | } |
1031 | case UST_STOP_TRACE: | |
1032 | { | |
5461b305 DG |
1033 | /* Setup lttng message with no payload */ |
1034 | ret = setup_lttng_msg(cmd_ctx, 0); | |
1035 | if (ret < 0) { | |
1036 | goto setup_error; | |
1037 | } | |
ca95a216 | 1038 | |
5461b305 DG |
1039 | ret = ust_stop_trace(cmd_ctx); |
1040 | if (ret < 0) { | |
1041 | goto setup_error; | |
1042 | } | |
1043 | break; | |
5e16da05 MD |
1044 | } |
1045 | case LTTNG_LIST_SESSIONS: | |
1046 | { | |
5461b305 DG |
1047 | unsigned int session_count; |
1048 | ||
1049 | session_count = get_session_count(); | |
5e16da05 MD |
1050 | if (session_count == 0) { |
1051 | ret = LTTCOMM_NO_SESS; | |
5461b305 | 1052 | goto error; |
57167058 | 1053 | } |
5e16da05 | 1054 | |
5461b305 DG |
1055 | ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) * session_count); |
1056 | if (ret < 0) { | |
1057 | goto setup_error; | |
e065084a | 1058 | } |
5e16da05 | 1059 | |
5461b305 | 1060 | get_lttng_session((struct lttng_session *)(cmd_ctx->llm->payload)); |
5e16da05 | 1061 | |
5461b305 | 1062 | ret = LTTCOMM_OK; |
5e16da05 MD |
1063 | break; |
1064 | } | |
1065 | default: | |
1066 | /* Undefined command */ | |
5461b305 DG |
1067 | ret = setup_lttng_msg(cmd_ctx, 0); |
1068 | if (ret < 0) { | |
1069 | goto setup_error; | |
1070 | } | |
1071 | ||
5e16da05 | 1072 | ret = LTTCOMM_UND; |
5461b305 | 1073 | break; |
fac6795d DG |
1074 | } |
1075 | ||
5461b305 DG |
1076 | /* Set return code */ |
1077 | cmd_ctx->llm->ret_code = ret; | |
ca95a216 | 1078 | |
e065084a DG |
1079 | return ret; |
1080 | ||
5461b305 | 1081 | error: |
5461b305 DG |
1082 | if (cmd_ctx->llm == NULL) { |
1083 | DBG("Missing llm structure. Allocating one."); | |
894be886 | 1084 | if (setup_lttng_msg(cmd_ctx, 0) < 0) { |
5461b305 DG |
1085 | goto setup_error; |
1086 | } | |
1087 | } | |
e065084a | 1088 | /* Notify client of error */ |
5461b305 | 1089 | cmd_ctx->llm->ret_code = ret; |
e065084a | 1090 | |
5461b305 | 1091 | setup_error: |
8028d920 | 1092 | return ret; |
fac6795d DG |
1093 | } |
1094 | ||
1d4b027a DG |
1095 | /* |
1096 | * thread_manage_clients | |
1097 | * | |
1098 | * This thread manage all clients request using the unix | |
1099 | * client socket for communication. | |
1100 | */ | |
1101 | static void *thread_manage_clients(void *data) | |
1102 | { | |
1103 | int sock, ret; | |
1104 | struct command_ctx *cmd_ctx; | |
1105 | ||
1106 | DBG("[thread] Manage client started"); | |
1107 | ||
1108 | ret = lttcomm_listen_unix_sock(client_sock); | |
1109 | if (ret < 0) { | |
1110 | goto error; | |
1111 | } | |
1112 | ||
1113 | /* Notify parent pid that we are ready | |
1114 | * to accept command for client side. | |
1115 | */ | |
1116 | if (opt_sig_parent) { | |
1117 | kill(ppid, SIGCHLD); | |
1118 | } | |
1119 | ||
1120 | while (1) { | |
1121 | /* Blocking call, waiting for transmission */ | |
1122 | DBG("Accepting client command ..."); | |
1123 | sock = lttcomm_accept_unix_sock(client_sock); | |
1124 | if (sock < 0) { | |
1125 | goto error; | |
1126 | } | |
1127 | ||
1128 | /* Allocate context command to process the client request */ | |
1129 | cmd_ctx = malloc(sizeof(struct command_ctx)); | |
1130 | ||
1131 | /* Allocate data buffer for reception */ | |
1132 | cmd_ctx->lsm = malloc(sizeof(struct lttcomm_session_msg)); | |
1133 | cmd_ctx->llm = NULL; | |
1134 | cmd_ctx->session = NULL; | |
1135 | ||
1136 | /* | |
1137 | * Data is received from the lttng client. The struct | |
1138 | * lttcomm_session_msg (lsm) contains the command and data request of | |
1139 | * the client. | |
1140 | */ | |
1141 | DBG("Receiving data from client ..."); | |
1142 | ret = lttcomm_recv_unix_sock(sock, cmd_ctx->lsm, sizeof(struct lttcomm_session_msg)); | |
1143 | if (ret <= 0) { | |
1144 | continue; | |
1145 | } | |
1146 | ||
1147 | /* | |
1148 | * This function dispatch the work to the kernel or userspace tracer | |
1149 | * libs and fill the lttcomm_lttng_msg data structure of all the needed | |
1150 | * informations for the client. The command context struct contains | |
1151 | * everything this function may needs. | |
1152 | */ | |
1153 | ret = process_client_msg(cmd_ctx); | |
1154 | if (ret < 0) { | |
1155 | /* TODO: Inform client somehow of the fatal error. At this point, | |
1156 | * ret < 0 means that a malloc failed (ENOMEM). */ | |
1157 | /* Error detected but still accept command */ | |
1158 | clean_command_ctx(cmd_ctx); | |
1159 | continue; | |
1160 | } | |
1161 | ||
1162 | DBG("Sending response (size: %d, retcode: %d)", | |
1163 | cmd_ctx->lttng_msg_size, cmd_ctx->llm->ret_code); | |
1164 | ret = send_unix_sock(sock, cmd_ctx->llm, cmd_ctx->lttng_msg_size); | |
1165 | if (ret < 0) { | |
1166 | ERR("Failed to send data back to client"); | |
1167 | } | |
1168 | ||
1169 | clean_command_ctx(cmd_ctx); | |
1170 | } | |
1171 | ||
1172 | error: | |
1173 | return NULL; | |
1174 | } | |
1175 | ||
1176 | ||
fac6795d DG |
1177 | /* |
1178 | * usage function on stderr | |
1179 | */ | |
1180 | static void usage(void) | |
1181 | { | |
b716ce68 | 1182 | fprintf(stderr, "Usage: %s OPTIONS\n\nOptions:\n", progname); |
d6f42150 DG |
1183 | fprintf(stderr, " -h, --help Display this usage.\n"); |
1184 | fprintf(stderr, " -c, --client-sock PATH Specify path for the client unix socket\n"); | |
1185 | fprintf(stderr, " -a, --apps-sock PATH Specify path for apps unix socket\n"); | |
1186 | fprintf(stderr, " --kconsumerd-err-sock PATH Specify path for the kernel consumer error socket\n"); | |
1187 | fprintf(stderr, " --kconsumerd-cmd-sock PATH Specify path for the kernel consumer command socket\n"); | |
1188 | fprintf(stderr, " -d, --daemonize Start as a daemon.\n"); | |
1189 | fprintf(stderr, " -g, --group NAME Specify the tracing group name. (default: tracing)\n"); | |
1190 | fprintf(stderr, " -V, --version Show version number.\n"); | |
1191 | fprintf(stderr, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n"); | |
1192 | fprintf(stderr, " -q, --quiet No output at all.\n"); | |
1193 | fprintf(stderr, " -v, --verbose Verbose mode. Activate DBG() macro.\n"); | |
fac6795d DG |
1194 | } |
1195 | ||
1196 | /* | |
1197 | * daemon argument parsing | |
1198 | */ | |
1199 | static int parse_args(int argc, char **argv) | |
1200 | { | |
1201 | int c; | |
1202 | ||
1203 | static struct option long_options[] = { | |
1204 | { "client-sock", 1, 0, 'c' }, | |
1205 | { "apps-sock", 1, 0, 'a' }, | |
d6f42150 DG |
1206 | { "kconsumerd-cmd-sock", 1, 0, 0 }, |
1207 | { "kconsumerd-err-sock", 1, 0, 0 }, | |
fac6795d | 1208 | { "daemonize", 0, 0, 'd' }, |
5b8719f5 | 1209 | { "sig-parent", 0, 0, 'S' }, |
fac6795d DG |
1210 | { "help", 0, 0, 'h' }, |
1211 | { "group", 1, 0, 'g' }, | |
1212 | { "version", 0, 0, 'V' }, | |
75462a81 | 1213 | { "quiet", 0, 0, 'q' }, |
3f9947db | 1214 | { "verbose", 0, 0, 'v' }, |
fac6795d DG |
1215 | { NULL, 0, 0, 0 } |
1216 | }; | |
1217 | ||
1218 | while (1) { | |
1219 | int option_index = 0; | |
d6f42150 | 1220 | c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:E:C:", long_options, &option_index); |
fac6795d DG |
1221 | if (c == -1) { |
1222 | break; | |
1223 | } | |
1224 | ||
1225 | switch (c) { | |
1226 | case 0: | |
1227 | fprintf(stderr, "option %s", long_options[option_index].name); | |
1228 | if (optarg) { | |
1229 | fprintf(stderr, " with arg %s\n", optarg); | |
1230 | } | |
1231 | break; | |
b716ce68 | 1232 | case 'c': |
fac6795d DG |
1233 | snprintf(client_unix_sock_path, PATH_MAX, "%s", optarg); |
1234 | break; | |
1235 | case 'a': | |
1236 | snprintf(apps_unix_sock_path, PATH_MAX, "%s", optarg); | |
1237 | break; | |
1238 | case 'd': | |
1239 | opt_daemon = 1; | |
1240 | break; | |
1241 | case 'g': | |
1242 | opt_tracing_group = strdup(optarg); | |
1243 | break; | |
1244 | case 'h': | |
1245 | usage(); | |
1246 | exit(EXIT_FAILURE); | |
1247 | case 'V': | |
1248 | fprintf(stdout, "%s\n", VERSION); | |
1249 | exit(EXIT_SUCCESS); | |
5b8719f5 DG |
1250 | case 'S': |
1251 | opt_sig_parent = 1; | |
1252 | break; | |
d6f42150 DG |
1253 | case 'E': |
1254 | snprintf(kconsumerd_err_unix_sock_path, PATH_MAX, "%s", optarg); | |
1255 | break; | |
1256 | case 'C': | |
1257 | snprintf(kconsumerd_cmd_unix_sock_path, PATH_MAX, "%s", optarg); | |
1258 | break; | |
75462a81 DG |
1259 | case 'q': |
1260 | opt_quiet = 1; | |
1261 | break; | |
3f9947db DG |
1262 | case 'v': |
1263 | opt_verbose = 1; | |
1264 | break; | |
fac6795d DG |
1265 | default: |
1266 | /* Unknown option or other error. | |
1267 | * Error is printed by getopt, just return */ | |
1268 | return -1; | |
1269 | } | |
1270 | } | |
1271 | ||
1272 | return 0; | |
1273 | } | |
1274 | ||
1275 | /* | |
1276 | * init_daemon_socket | |
1277 | * | |
1278 | * Creates the two needed socket by the daemon. | |
d6f42150 DG |
1279 | * apps_sock - The communication socket for all UST apps. |
1280 | * client_sock - The communication of the cli tool (lttng). | |
fac6795d DG |
1281 | */ |
1282 | static int init_daemon_socket() | |
1283 | { | |
1284 | int ret = 0; | |
1285 | mode_t old_umask; | |
1286 | ||
1287 | old_umask = umask(0); | |
1288 | ||
1289 | /* Create client tool unix socket */ | |
d6f42150 DG |
1290 | client_sock = lttcomm_create_unix_sock(client_unix_sock_path); |
1291 | if (client_sock < 0) { | |
1292 | ERR("Create unix sock failed: %s", client_unix_sock_path); | |
fac6795d DG |
1293 | ret = -1; |
1294 | goto end; | |
1295 | } | |
1296 | ||
1297 | /* File permission MUST be 660 */ | |
1298 | ret = chmod(client_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); | |
1299 | if (ret < 0) { | |
d6f42150 | 1300 | ERR("Set file permissions failed: %s", client_unix_sock_path); |
fac6795d DG |
1301 | perror("chmod"); |
1302 | goto end; | |
1303 | } | |
1304 | ||
1305 | /* Create the application unix socket */ | |
d6f42150 DG |
1306 | apps_sock = lttcomm_create_unix_sock(apps_unix_sock_path); |
1307 | if (apps_sock < 0) { | |
1308 | ERR("Create unix sock failed: %s", apps_unix_sock_path); | |
fac6795d DG |
1309 | ret = -1; |
1310 | goto end; | |
1311 | } | |
1312 | ||
d6f42150 | 1313 | /* File permission MUST be 666 */ |
fac6795d DG |
1314 | ret = chmod(apps_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
1315 | if (ret < 0) { | |
d6f42150 | 1316 | ERR("Set file permissions failed: %s", apps_unix_sock_path); |
fac6795d DG |
1317 | perror("chmod"); |
1318 | goto end; | |
1319 | } | |
1320 | ||
1321 | end: | |
1322 | umask(old_umask); | |
1323 | return ret; | |
1324 | } | |
1325 | ||
1326 | /* | |
1327 | * check_existing_daemon | |
1328 | * | |
1329 | * Check if the global socket is available. | |
62bd06d8 | 1330 | * If yes, error is returned. |
fac6795d DG |
1331 | */ |
1332 | static int check_existing_daemon() | |
1333 | { | |
1334 | int ret; | |
1335 | ||
1336 | ret = access(client_unix_sock_path, F_OK); | |
1337 | if (ret == 0) { | |
1338 | ret = access(apps_unix_sock_path, F_OK); | |
1339 | } | |
1340 | ||
1341 | return ret; | |
1342 | } | |
1343 | ||
1344 | /* | |
62bd06d8 | 1345 | * get_home_dir |
fac6795d | 1346 | * |
62bd06d8 DG |
1347 | * Return pointer to home directory path using |
1348 | * the env variable HOME. | |
fac6795d | 1349 | * |
62bd06d8 | 1350 | * Default : /tmp |
fac6795d DG |
1351 | */ |
1352 | static const char *get_home_dir(void) | |
1353 | { | |
1354 | const char *home_path; | |
1355 | ||
686204ab | 1356 | if ((home_path = (const char *) getenv("HOME")) == NULL) { |
fac6795d DG |
1357 | home_path = default_home_dir; |
1358 | } | |
1359 | ||
1360 | return home_path; | |
1361 | } | |
1362 | ||
1363 | /* | |
d6f42150 | 1364 | * set_permissions |
fac6795d | 1365 | * |
5e16da05 MD |
1366 | * Set the tracing group gid onto the client socket. |
1367 | * | |
1368 | * Race window between mkdir and chown is OK because we are going from | |
1369 | * less permissive (root.root) to more permissive (root.tracing). | |
fac6795d | 1370 | */ |
d6f42150 | 1371 | static int set_permissions(void) |
fac6795d DG |
1372 | { |
1373 | int ret; | |
1374 | struct group *grp; | |
1375 | ||
1376 | /* Decide which group name to use */ | |
1377 | (opt_tracing_group != NULL) ? | |
1378 | (grp = getgrnam(opt_tracing_group)) : | |
1379 | (grp = getgrnam(default_tracing_group)); | |
1380 | ||
1381 | if (grp == NULL) { | |
75462a81 | 1382 | ERR("Missing tracing group. Aborting execution.\n"); |
fac6795d DG |
1383 | ret = -1; |
1384 | goto end; | |
1385 | } | |
1386 | ||
d6f42150 DG |
1387 | /* Set lttng run dir */ |
1388 | ret = chown(LTTNG_RUNDIR, 0, grp->gr_gid); | |
1389 | if (ret < 0) { | |
1390 | ERR("Unable to set group on " LTTNG_RUNDIR); | |
1391 | perror("chown"); | |
1392 | } | |
1393 | ||
1394 | /* lttng client socket path */ | |
fac6795d DG |
1395 | ret = chown(client_unix_sock_path, 0, grp->gr_gid); |
1396 | if (ret < 0) { | |
d6f42150 DG |
1397 | ERR("Unable to set group on %s", client_unix_sock_path); |
1398 | perror("chown"); | |
1399 | } | |
1400 | ||
1401 | /* kconsumerd error socket path */ | |
1402 | ret = chown(kconsumerd_err_unix_sock_path, 0, grp->gr_gid); | |
1403 | if (ret < 0) { | |
1404 | ERR("Unable to set group on %s", kconsumerd_err_unix_sock_path); | |
fac6795d DG |
1405 | perror("chown"); |
1406 | } | |
1407 | ||
d6f42150 | 1408 | DBG("All permissions are set"); |
e07ae692 | 1409 | |
fac6795d DG |
1410 | end: |
1411 | return ret; | |
1412 | } | |
1413 | ||
d6f42150 DG |
1414 | /* |
1415 | * create_lttng_rundir | |
1416 | * | |
1417 | * Create the lttng run directory needed for all | |
1418 | * global sockets and pipe. | |
1419 | */ | |
1420 | static int create_lttng_rundir(void) | |
1421 | { | |
1422 | int ret; | |
1423 | ||
1424 | ret = mkdir(LTTNG_RUNDIR, S_IRWXU | S_IRWXG ); | |
1425 | if (ret < 0) { | |
1426 | ERR("Unable to create " LTTNG_RUNDIR); | |
1427 | goto error; | |
1428 | } | |
1429 | ||
1430 | error: | |
1431 | return ret; | |
1432 | } | |
1433 | ||
20fe2104 DG |
1434 | /* |
1435 | * init_kernel_tracer | |
1436 | * | |
1437 | * Setup necessary data for kernel tracer action. | |
1438 | */ | |
1439 | static void init_kernel_tracer(void) | |
1440 | { | |
1441 | /* Set the global kernel tracer fd */ | |
1442 | kernel_tracer_fd = open(DEFAULT_KERNEL_TRACER_PATH, O_RDWR); | |
1443 | if (kernel_tracer_fd < 0) { | |
1444 | WARN("No kernel tracer available"); | |
1445 | kernel_tracer_fd = 0; | |
1446 | } | |
8c0faa1d DG |
1447 | |
1448 | DBG("Kernel tracer fd %d", kernel_tracer_fd); | |
20fe2104 DG |
1449 | } |
1450 | ||
d6f42150 DG |
1451 | /* |
1452 | * set_kconsumerd_sockets | |
1453 | * | |
1454 | * Setup sockets and directory needed by the kconsumerd | |
1455 | * communication with the session daemon. | |
1456 | */ | |
1457 | static int set_kconsumerd_sockets(void) | |
1458 | { | |
1459 | int ret; | |
1460 | ||
1461 | if (strlen(kconsumerd_err_unix_sock_path) == 0) { | |
1462 | snprintf(kconsumerd_err_unix_sock_path, PATH_MAX, KCONSUMERD_ERR_SOCK_PATH); | |
1463 | } | |
1464 | ||
1465 | if (strlen(kconsumerd_cmd_unix_sock_path) == 0) { | |
1466 | snprintf(kconsumerd_cmd_unix_sock_path, PATH_MAX, KCONSUMERD_CMD_SOCK_PATH); | |
1467 | } | |
1468 | ||
1469 | ret = mkdir(KCONSUMERD_PATH, S_IRWXU | S_IRWXG); | |
1470 | if (ret < 0) { | |
1471 | ERR("Failed to create " KCONSUMERD_PATH); | |
1472 | goto error; | |
1473 | } | |
1474 | ||
1475 | /* Create the kconsumerd error unix socket */ | |
1476 | kconsumerd_err_sock = lttcomm_create_unix_sock(kconsumerd_err_unix_sock_path); | |
1477 | if (kconsumerd_err_sock < 0) { | |
1478 | ERR("Create unix sock failed: %s", kconsumerd_err_unix_sock_path); | |
1479 | ret = -1; | |
1480 | goto error; | |
1481 | } | |
1482 | ||
1483 | /* File permission MUST be 660 */ | |
1484 | ret = chmod(kconsumerd_err_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); | |
1485 | if (ret < 0) { | |
1486 | ERR("Set file permissions failed: %s", kconsumerd_err_unix_sock_path); | |
1487 | perror("chmod"); | |
1488 | goto error; | |
1489 | } | |
1490 | ||
1491 | error: | |
1492 | return ret; | |
1493 | } | |
1494 | ||
fac6795d | 1495 | /* |
62bd06d8 | 1496 | * sighandler |
fac6795d | 1497 | * |
62bd06d8 | 1498 | * Signal handler for the daemon |
fac6795d DG |
1499 | */ |
1500 | static void sighandler(int sig) | |
1501 | { | |
1502 | switch (sig) { | |
1503 | case SIGPIPE: | |
e07ae692 | 1504 | DBG("SIGPIPE catched"); |
87378cf5 | 1505 | return; |
fac6795d | 1506 | case SIGINT: |
e07ae692 DG |
1507 | DBG("SIGINT catched"); |
1508 | cleanup(); | |
1509 | break; | |
fac6795d | 1510 | case SIGTERM: |
e07ae692 | 1511 | DBG("SIGTERM catched"); |
fac6795d | 1512 | cleanup(); |
686204ab | 1513 | break; |
fac6795d DG |
1514 | default: |
1515 | break; | |
1516 | } | |
1517 | ||
1518 | exit(EXIT_SUCCESS); | |
1519 | } | |
1520 | ||
1521 | /* | |
1d4b027a | 1522 | * set_signal_handler |
fac6795d | 1523 | * |
1d4b027a DG |
1524 | * Setup signal handler for : |
1525 | * SIGINT, SIGTERM, SIGPIPE | |
fac6795d | 1526 | */ |
1d4b027a | 1527 | static int set_signal_handler(void) |
fac6795d | 1528 | { |
1d4b027a DG |
1529 | int ret = 0; |
1530 | struct sigaction sa; | |
1531 | sigset_t sigset; | |
fac6795d | 1532 | |
1d4b027a DG |
1533 | if ((ret = sigemptyset(&sigset)) < 0) { |
1534 | perror("sigemptyset"); | |
1535 | return ret; | |
1536 | } | |
d6f42150 | 1537 | |
1d4b027a DG |
1538 | sa.sa_handler = sighandler; |
1539 | sa.sa_mask = sigset; | |
1540 | sa.sa_flags = 0; | |
1541 | if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { | |
1542 | perror("sigaction"); | |
1543 | return ret; | |
d6f42150 DG |
1544 | } |
1545 | ||
1d4b027a DG |
1546 | if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) { |
1547 | perror("sigaction"); | |
1548 | return ret; | |
d6f42150 | 1549 | } |
aaf26714 | 1550 | |
1d4b027a DG |
1551 | if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) { |
1552 | perror("sigaction"); | |
1553 | return ret; | |
8c0faa1d DG |
1554 | } |
1555 | ||
1d4b027a DG |
1556 | DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT"); |
1557 | ||
1558 | return ret; | |
fac6795d DG |
1559 | } |
1560 | ||
1561 | /* | |
1562 | * main | |
1563 | */ | |
1564 | int main(int argc, char **argv) | |
1565 | { | |
fac6795d DG |
1566 | int ret = 0; |
1567 | void *status; | |
fac6795d DG |
1568 | |
1569 | /* Parse arguments */ | |
1570 | progname = argv[0]; | |
1571 | if ((ret = parse_args(argc, argv) < 0)) { | |
1572 | goto error; | |
1573 | } | |
1574 | ||
1575 | /* Daemonize */ | |
1576 | if (opt_daemon) { | |
53094c05 DG |
1577 | ret = daemon(0, 0); |
1578 | if (ret < 0) { | |
1579 | perror("daemon"); | |
1580 | goto error; | |
1581 | } | |
fac6795d DG |
1582 | } |
1583 | ||
1584 | /* Check if daemon is UID = 0 */ | |
1585 | is_root = !getuid(); | |
1586 | ||
1587 | /* Set all sockets path */ | |
1588 | if (is_root) { | |
d6f42150 DG |
1589 | ret = create_lttng_rundir(); |
1590 | if (ret < 0) { | |
1591 | goto error; | |
1592 | } | |
1593 | ||
fac6795d | 1594 | if (strlen(apps_unix_sock_path) == 0) { |
d6f42150 DG |
1595 | snprintf(apps_unix_sock_path, PATH_MAX, |
1596 | DEFAULT_GLOBAL_APPS_UNIX_SOCK); | |
fac6795d DG |
1597 | } |
1598 | ||
1599 | if (strlen(client_unix_sock_path) == 0) { | |
d6f42150 DG |
1600 | snprintf(client_unix_sock_path, PATH_MAX, |
1601 | DEFAULT_GLOBAL_CLIENT_UNIX_SOCK); | |
1602 | } | |
1603 | ||
1604 | ret = set_kconsumerd_sockets(); | |
1605 | if (ret < 0) { | |
1606 | goto error; | |
fac6795d | 1607 | } |
20fe2104 DG |
1608 | |
1609 | /* Setup kernel tracer */ | |
1610 | init_kernel_tracer(); | |
fac6795d DG |
1611 | } else { |
1612 | if (strlen(apps_unix_sock_path) == 0) { | |
d6f42150 DG |
1613 | snprintf(apps_unix_sock_path, PATH_MAX, |
1614 | DEFAULT_HOME_APPS_UNIX_SOCK, get_home_dir()); | |
fac6795d DG |
1615 | } |
1616 | ||
1617 | /* Set the cli tool unix socket path */ | |
1618 | if (strlen(client_unix_sock_path) == 0) { | |
d6f42150 DG |
1619 | snprintf(client_unix_sock_path, PATH_MAX, |
1620 | DEFAULT_HOME_CLIENT_UNIX_SOCK, get_home_dir()); | |
fac6795d DG |
1621 | } |
1622 | } | |
1623 | ||
847177cd DG |
1624 | DBG("Client socket path %s", client_unix_sock_path); |
1625 | DBG("Application socket path %s", apps_unix_sock_path); | |
1626 | ||
fac6795d DG |
1627 | /* See if daemon already exist. If any of the two |
1628 | * socket needed by the daemon are present, this test fails | |
1629 | */ | |
1630 | if ((ret = check_existing_daemon()) == 0) { | |
75462a81 | 1631 | ERR("Already running daemon.\n"); |
ab118b20 | 1632 | /* We do not goto error because we must not |
d6f42150 | 1633 | * cleanup() because a daemon is already running. |
ab118b20 | 1634 | */ |
5e16da05 | 1635 | exit(EXIT_FAILURE); |
fac6795d DG |
1636 | } |
1637 | ||
1638 | if (set_signal_handler() < 0) { | |
1639 | goto error; | |
1640 | } | |
1641 | ||
d6f42150 | 1642 | /* Setup the needed unix socket */ |
fac6795d DG |
1643 | if (init_daemon_socket() < 0) { |
1644 | goto error; | |
1645 | } | |
1646 | ||
1647 | /* Set credentials to socket */ | |
d6f42150 | 1648 | if (is_root && (set_permissions() < 0)) { |
fac6795d DG |
1649 | goto error; |
1650 | } | |
1651 | ||
5b8719f5 DG |
1652 | /* Get parent pid if -S, --sig-parent is specified. */ |
1653 | if (opt_sig_parent) { | |
1654 | ppid = getppid(); | |
1655 | } | |
1656 | ||
fac6795d DG |
1657 | while (1) { |
1658 | /* Create thread to manage the client socket */ | |
1d4b027a | 1659 | ret = pthread_create(&client_thread, NULL, thread_manage_clients, (void *) NULL); |
fac6795d DG |
1660 | if (ret != 0) { |
1661 | perror("pthread_create"); | |
1662 | goto error; | |
1663 | } | |
1664 | ||
1665 | /* Create thread to manage application socket */ | |
1d4b027a | 1666 | ret = pthread_create(&apps_thread, NULL, thread_manage_apps, (void *) NULL); |
fac6795d DG |
1667 | if (ret != 0) { |
1668 | perror("pthread_create"); | |
1669 | goto error; | |
1670 | } | |
1671 | ||
1d4b027a DG |
1672 | ret = pthread_join(client_thread, &status); |
1673 | if (ret != 0) { | |
1674 | perror("pthread_join"); | |
1675 | goto error; | |
fac6795d DG |
1676 | } |
1677 | } | |
1678 | ||
1679 | cleanup(); | |
5e16da05 | 1680 | exit(EXIT_SUCCESS); |
fac6795d DG |
1681 | |
1682 | error: | |
1683 | cleanup(); | |
5e16da05 | 1684 | exit(EXIT_FAILURE); |
fac6795d | 1685 | } |