Add lttng-modules detection for tests
[lttng-tools.git] / liblttngctl / lttngctl.c
CommitLineData
826d496d 1/*
82a3637f
DG
2 * liblttngctl.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
826d496d 6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
fac6795d 7 *
82a3637f
DG
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
fac6795d 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82a3637f
DG
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
fac6795d
DG
21 */
22
23#define _GNU_SOURCE
24#include <errno.h>
25#include <grp.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <unistd.h>
30
5b97ec60 31#include <lttng/lttng.h>
fac6795d 32
e88129fc 33#include <lttng-sessiond-comm.h>
fac6795d 34#include "lttngerr.h"
f3ed775e 35#include "lttng-share.h"
fac6795d
DG
36
37/* Socket to session daemon for communication */
38static int sessiond_socket;
39static char sessiond_sock_path[PATH_MAX];
40
fac6795d
DG
41/* Variables */
42static char *tracing_group;
43static int connected;
44
99497cd0
MD
45/*
46 * Copy string from src to dst and enforce null terminated byte.
47 */
48static void copy_string(char *dst, const char *src, size_t len)
49{
e7d6716d 50 if (src && dst) {
99497cd0
MD
51 strncpy(dst, src, len);
52 /* Enforce the NULL terminated byte */
53 dst[len - 1] = '\0';
cd80958d
DG
54 } else if (dst) {
55 dst[0] = '\0';
99497cd0
MD
56 }
57}
58
fac6795d 59/*
cd80958d 60 * Copy domain to lttcomm_session_msg domain.
fac6795d 61 *
cd80958d
DG
62 * If domain is unknown, default domain will be the kernel.
63 */
64static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src)
65{
66 if (src && dst) {
67 switch (src->type) {
68 case LTTNG_DOMAIN_KERNEL:
69 case LTTNG_DOMAIN_UST:
70 case LTTNG_DOMAIN_UST_EXEC_NAME:
71 case LTTNG_DOMAIN_UST_PID:
72 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
73 memcpy(dst, src, sizeof(struct lttng_domain));
74 break;
75 default:
76 dst->type = LTTNG_DOMAIN_KERNEL;
77 break;
78 }
79 }
80}
81
82/*
83 * Send lttcomm_session_msg to the session daemon.
fac6795d 84 *
cd80958d
DG
85 * On success, return 0
86 * On error, return error code
fac6795d 87 */
cd80958d 88static int send_session_msg(struct lttcomm_session_msg *lsm)
fac6795d
DG
89{
90 int ret;
91
92 if (!connected) {
e065084a
DG
93 ret = -ENOTCONN;
94 goto end;
fac6795d
DG
95 }
96
cd80958d
DG
97 ret = lttcomm_send_unix_sock(sessiond_socket, lsm,
98 sizeof(struct lttcomm_session_msg));
e065084a
DG
99
100end:
101 return ret;
102}
103
104/*
cd80958d 105 * Receive data from the sessiond socket.
e065084a 106 *
cd80958d
DG
107 * On success, return 0
108 * On error, return recv() error code
e065084a 109 */
ca95a216 110static int recv_data_sessiond(void *buf, size_t len)
e065084a
DG
111{
112 int ret;
113
114 if (!connected) {
115 ret = -ENOTCONN;
116 goto end;
fac6795d
DG
117 }
118
ca95a216 119 ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len);
fac6795d 120
e065084a 121end:
fac6795d
DG
122 return ret;
123}
124
125/*
947308c4 126 * Check if the specified group name exist.
65beb5ff
DG
127 *
128 * If yes return 0, else return -1.
947308c4
DG
129 */
130static int check_tracing_group(const char *grp_name)
131{
132 struct group *grp_tracing; /* no free(). See getgrnam(3) */
133 gid_t *grp_list;
134 int grp_list_size, grp_id, i;
135 int ret = -1;
136
137 /* Get GID of group 'tracing' */
138 grp_tracing = getgrnam(grp_name);
139 if (grp_tracing == NULL) {
140 /* NULL means not found also. getgrnam(3) */
141 if (errno != 0) {
142 perror("getgrnam");
143 }
144 goto end;
145 }
146
147 /* Get number of supplementary group IDs */
148 grp_list_size = getgroups(0, NULL);
149 if (grp_list_size < 0) {
150 perror("getgroups");
151 goto end;
152 }
153
154 /* Alloc group list of the right size */
155 grp_list = malloc(grp_list_size * sizeof(gid_t));
156 grp_id = getgroups(grp_list_size, grp_list);
157 if (grp_id < -1) {
158 perror("getgroups");
159 goto free_list;
160 }
161
162 for (i = 0; i < grp_list_size; i++) {
163 if (grp_list[i] == grp_tracing->gr_gid) {
164 ret = 0;
165 break;
166 }
167 }
168
169free_list:
170 free(grp_list);
171
172end:
173 return ret;
174}
175
176/*
65beb5ff
DG
177 * Set sessiond socket path by putting it in the global sessiond_sock_path
178 * variable.
947308c4
DG
179 */
180static int set_session_daemon_path(void)
181{
182 int ret;
183
184 /* Are we in the tracing group ? */
185 ret = check_tracing_group(tracing_group);
186 if (ret < 0 && getuid() != 0) {
99497cd0 187 if (snprintf(sessiond_sock_path, PATH_MAX,
cd80958d
DG
188 DEFAULT_HOME_CLIENT_UNIX_SOCK,
189 getenv("HOME")) < 0) {
947308c4
DG
190 return -ENOMEM;
191 }
192 } else {
cd80958d
DG
193 copy_string(sessiond_sock_path,
194 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
195 PATH_MAX);
947308c4
DG
196 }
197
198 return 0;
199}
200
65beb5ff
DG
201/*
202 * Connect to the LTTng session daemon.
203 *
204 * On success, return 0. On error, return -1.
205 */
206static int connect_sessiond(void)
207{
208 int ret;
209
210 ret = set_session_daemon_path();
211 if (ret < 0) {
212 return ret;
213 }
214
215 /* Connect to the sesssion daemon */
216 ret = lttcomm_connect_unix_sock(sessiond_sock_path);
217 if (ret < 0) {
218 return ret;
219 }
220
221 sessiond_socket = ret;
222 connected = 1;
223
224 return 0;
225}
226
227/*
228 * Clean disconnect the session daemon.
229 */
230static int disconnect_sessiond(void)
231{
232 int ret = 0;
233
234 if (connected) {
235 ret = lttcomm_close_unix_sock(sessiond_socket);
236 sessiond_socket = 0;
237 connected = 0;
238 }
239
240 return ret;
241}
242
35a6fdb7 243/*
cd80958d 244 * Ask the session daemon a specific command and put the data into buf.
65beb5ff 245 *
cd80958d 246 * Return size of data (only payload, not header).
65beb5ff 247 */
cd80958d 248static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
65beb5ff
DG
249{
250 int ret;
251 size_t size;
252 void *data = NULL;
cd80958d 253 struct lttcomm_lttng_msg llm;
65beb5ff
DG
254
255 ret = connect_sessiond();
256 if (ret < 0) {
257 goto end;
258 }
259
65beb5ff 260 /* Send command to session daemon */
cd80958d 261 ret = send_session_msg(lsm);
65beb5ff
DG
262 if (ret < 0) {
263 goto end;
264 }
265
266 /* Get header from data transmission */
267 ret = recv_data_sessiond(&llm, sizeof(llm));
268 if (ret < 0) {
269 goto end;
270 }
271
272 /* Check error code if OK */
273 if (llm.ret_code != LTTCOMM_OK) {
274 ret = -llm.ret_code;
275 goto end;
276 }
277
278 size = llm.data_size;
279 if (size == 0) {
7d29a247 280 ret = 0;
65beb5ff
DG
281 goto end;
282 }
283
284 data = (void*) malloc(size);
285
286 /* Get payload data */
287 ret = recv_data_sessiond(data, size);
288 if (ret < 0) {
289 free(data);
290 goto end;
291 }
292
293 *buf = data;
294 ret = size;
295
296end:
297 disconnect_sessiond();
298 return ret;
299}
300
9f19cc17 301/*
cd80958d 302 * Create lttng handle and return pointer.
9f19cc17 303 */
cd80958d
DG
304struct lttng_handle *lttng_create_handle(const char *session_name,
305 struct lttng_domain *domain)
9f19cc17 306{
cd80958d
DG
307 struct lttng_handle *handle;
308
309 handle = malloc(sizeof(struct lttng_handle));
310 if (handle == NULL) {
311 perror("malloc handle");
312 goto end;
313 }
314
315 /* Copy session name */
316 copy_string(handle->session_name, session_name,
317 sizeof(handle->session_name));
318
319 /* Copy lttng domain */
320 copy_lttng_domain(&handle->domain, domain);
321
322end:
323 return handle;
324}
325
326/*
327 * Destroy handle by free(3) the pointer.
328 */
329void lttng_destroy_handle(struct lttng_handle *handle)
330{
331 if (handle) {
332 free(handle);
eb354453
DG
333 }
334}
335
d9800920
DG
336/*
337 * Register an outside consumer.
338 */
339int lttng_register_consumer(struct lttng_handle *handle,
340 const char *socket_path)
341{
342 struct lttcomm_session_msg lsm;
343
344 lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
345 copy_string(lsm.session.name, handle->session_name,
346 sizeof(lsm.session.name));
347 copy_lttng_domain(&lsm.domain, &handle->domain);
348
349 copy_string(lsm.u.reg.path, socket_path, sizeof(lsm.u.reg.path));
350
351 return ask_sessiond(&lsm, NULL);
352}
353
1df4dedd 354/*
f3ed775e 355 * Start tracing for all trace of the session.
1df4dedd 356 */
cd80958d 357int lttng_start_tracing(struct lttng_handle *handle)
f3ed775e 358{
cd80958d
DG
359 struct lttcomm_session_msg lsm;
360
361 if (!handle) {
362 return -1;
363 }
364
365 lsm.cmd_type = LTTNG_START_TRACE;
366 copy_string(lsm.session.name, handle->session_name,
367 sizeof(lsm.session.name));
368
369 return ask_sessiond(&lsm, NULL);
f3ed775e 370}
1df4dedd
DG
371
372/*
f3ed775e
DG
373 * Stop tracing for all trace of the session.
374 */
cd80958d 375int lttng_stop_tracing(struct lttng_handle *handle)
f3ed775e 376{
cd80958d
DG
377 struct lttcomm_session_msg lsm;
378
379 lsm.cmd_type = LTTNG_STOP_TRACE;
380 copy_string(lsm.session.name, handle->session_name,
381 sizeof(lsm.session.name));
382
383 return ask_sessiond(&lsm, NULL);
f3ed775e
DG
384}
385
386/*
cd80958d 387 * Add context to event or/and channel.
1df4dedd 388 */
cd80958d 389int lttng_add_context(struct lttng_handle *handle,
38057ed1
DG
390 struct lttng_event_context *ctx, const char *event_name,
391 const char *channel_name)
d65106b1 392{
cd80958d
DG
393 struct lttcomm_session_msg lsm;
394
395 if (!handle) {
396 return -1;
397 }
398
399 lsm.cmd_type = LTTNG_ADD_CONTEXT;
400
401 /* Copy channel name */
402 copy_string(lsm.u.context.channel_name, channel_name,
403 sizeof(lsm.u.context.channel_name));
404 /* Copy event name */
405 copy_string(lsm.u.context.event_name, event_name,
406 sizeof(lsm.u.context.event_name));
407
408 copy_lttng_domain(&lsm.domain, &handle->domain);
d65106b1 409
eb354453
DG
410 if (ctx) {
411 memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
d65106b1
DG
412 }
413
cd80958d
DG
414 copy_string(lsm.session.name, handle->session_name,
415 sizeof(lsm.session.name));
416
417 return ask_sessiond(&lsm, NULL);
d65106b1
DG
418}
419
f3ed775e 420/*
cd80958d 421 * Enable event
f3ed775e 422 */
cd80958d 423int lttng_enable_event(struct lttng_handle *handle,
38057ed1 424 struct lttng_event *ev, const char *channel_name)
1df4dedd 425{
cd80958d
DG
426 struct lttcomm_session_msg lsm;
427
428 if (!handle) {
429 return -1;
430 }
33a2b854 431
94cf3c47 432 if (channel_name == NULL) {
cd80958d
DG
433 copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
434 sizeof(lsm.u.enable.channel_name));
33a2b854 435 } else {
cd80958d
DG
436 copy_string(lsm.u.enable.channel_name, channel_name,
437 sizeof(lsm.u.enable.channel_name));
eb354453
DG
438 }
439
cd80958d 440 copy_lttng_domain(&lsm.domain, &handle->domain);
0d0c377a 441
cd80958d
DG
442 if (ev) {
443 lsm.cmd_type = LTTNG_ENABLE_EVENT;
444 memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
0d0c377a 445 } else {
cd80958d 446 lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
f3ed775e
DG
447 }
448
cd80958d
DG
449 copy_string(lsm.session.name, handle->session_name,
450 sizeof(lsm.session.name));
451
452 return ask_sessiond(&lsm, NULL);
1df4dedd
DG
453}
454
455/*
f5177a38 456 * Disable event of a channel and domain.
1df4dedd 457 */
cd80958d 458int lttng_disable_event(struct lttng_handle *handle, const char *name,
38057ed1 459 const char *channel_name)
1df4dedd 460{
cd80958d 461 struct lttcomm_session_msg lsm;
1df4dedd 462
cd80958d
DG
463 if (!handle) {
464 return -1;
465 }
466
467 if (channel_name) {
468 copy_string(lsm.u.disable.channel_name, channel_name,
469 sizeof(lsm.u.disable.channel_name));
f3ed775e 470 } else {
cd80958d
DG
471 copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME,
472 sizeof(lsm.u.disable.channel_name));
eb354453
DG
473 }
474
cd80958d 475 copy_lttng_domain(&lsm.domain, &handle->domain);
f5177a38
DG
476
477 if (name == NULL) {
cd80958d
DG
478 copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name));
479 lsm.cmd_type = LTTNG_DISABLE_EVENT;
f5177a38 480 } else {
cd80958d 481 lsm.cmd_type = LTTNG_DISABLE_ALL_EVENT;
f3ed775e
DG
482 }
483
cd80958d
DG
484 copy_string(lsm.session.name, handle->session_name,
485 sizeof(lsm.session.name));
486
487 return ask_sessiond(&lsm, NULL);
1df4dedd
DG
488}
489
490/*
0d0c377a 491 * Enable channel per domain
a5c5a2bd 492 */
cd80958d 493int lttng_enable_channel(struct lttng_handle *handle,
38057ed1 494 struct lttng_channel *chan)
a5c5a2bd 495{
cd80958d
DG
496 struct lttcomm_session_msg lsm;
497
498 if (!handle) {
499 return -1;
500 }
501
eb354453 502 if (chan) {
cd80958d 503 memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
eb354453 504 }
7d29a247 505
cd80958d
DG
506 lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
507
508 copy_lttng_domain(&lsm.domain, &handle->domain);
7d29a247 509
cd80958d
DG
510 copy_string(lsm.session.name, handle->session_name,
511 sizeof(lsm.session.name));
512
513 return ask_sessiond(&lsm, NULL);
8c0faa1d 514}
1df4dedd 515
2ef84c95 516/*
0b97ec54 517 * All tracing will be stopped for registered events of the channel.
2ef84c95 518 */
cd80958d 519int lttng_disable_channel(struct lttng_handle *handle, const char *name)
2ef84c95 520{
cd80958d
DG
521 struct lttcomm_session_msg lsm;
522
523 if (!handle) {
524 return -1;
525 }
526
527 if (name) {
528 copy_string(lsm.u.disable.channel_name, name,
529 sizeof(lsm.u.disable.channel_name));
530 }
531
532 lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
1df4dedd 533
cd80958d
DG
534 copy_lttng_domain(&lsm.domain, &handle->domain);
535
536 copy_string(lsm.session.name, handle->session_name,
537 sizeof(lsm.session.name));
538
539 return ask_sessiond(&lsm, NULL);
ca95a216
DG
540}
541
fac6795d 542/*
2a71efd5 543 * List all available tracepoints of domain.
fac6795d 544 *
2a71efd5 545 * Return the size (bytes) of the list and set the events array.
7d29a247 546 * On error, return negative value.
fac6795d 547 */
cd80958d 548int lttng_list_tracepoints(struct lttng_handle *handle,
2a71efd5 549 struct lttng_event **events)
fac6795d 550{
052da939 551 int ret;
cd80958d
DG
552 struct lttcomm_session_msg lsm;
553
554 if (!handle) {
555 return -1;
556 }
fac6795d 557
cd80958d
DG
558 lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
559 copy_lttng_domain(&lsm.domain, &handle->domain);
2a71efd5 560
cd80958d 561 ret = ask_sessiond(&lsm, (void **) events);
052da939
DG
562 if (ret < 0) {
563 return ret;
eb354453 564 }
fac6795d 565
9f19cc17 566 return ret / sizeof(struct lttng_event);
fac6795d
DG
567}
568
1657e9bb 569/*
7d29a247 570 * Return a human readable string of code
1657e9bb 571 */
7d29a247 572const char *lttng_get_readable_code(int code)
1657e9bb 573{
7d29a247
DG
574 if (code > -LTTCOMM_OK) {
575 return "Ended with errors";
1657e9bb
DG
576 }
577
7d29a247 578 return lttcomm_get_readable_code(code);
1657e9bb
DG
579}
580
aaf97519 581/*
894be886 582 * Create a brand new session using name.
aaf97519 583 */
38057ed1 584int lttng_create_session(const char *name, const char *path)
aaf97519 585{
cd80958d
DG
586 struct lttcomm_session_msg lsm;
587
588 lsm.cmd_type = LTTNG_CREATE_SESSION;
589 copy_string(lsm.session.name, name, sizeof(lsm.session.name));
590 copy_string(lsm.session.path, path, sizeof(lsm.session.path));
591
592 return ask_sessiond(&lsm, NULL);
8028d920
DG
593}
594
595/*
8028d920
DG
596 * Destroy session using name.
597 */
cd80958d 598int lttng_destroy_session(struct lttng_handle *handle)
8028d920 599{
cd80958d
DG
600 struct lttcomm_session_msg lsm;
601
602 if (!handle) {
603 return -1;
604 }
605
606 lsm.cmd_type = LTTNG_DESTROY_SESSION;
607 copy_string(lsm.session.name, handle->session_name,
608 sizeof(lsm.session.name));
609
610 return ask_sessiond(&lsm, NULL);
aaf97519
DG
611}
612
57167058 613/*
57167058
DG
614 * Ask the session daemon for all available sessions.
615 *
ca95a216
DG
616 * Return number of session.
617 * On error, return negative value.
57167058 618 */
ca95a216 619int lttng_list_sessions(struct lttng_session **sessions)
57167058 620{
ca95a216 621 int ret;
cd80958d 622 struct lttcomm_session_msg lsm;
57167058 623
cd80958d
DG
624 lsm.cmd_type = LTTNG_LIST_SESSIONS;
625 ret = ask_sessiond(&lsm, (void**) sessions);
57167058 626 if (ret < 0) {
ca95a216 627 return ret;
57167058
DG
628 }
629
ca95a216 630 return ret / sizeof(struct lttng_session);
57167058
DG
631}
632
9f19cc17
DG
633/*
634 * List domain of a session.
635 */
cd80958d
DG
636int lttng_list_domains(struct lttng_handle *handle,
637 struct lttng_domain **domains)
9f19cc17
DG
638{
639 int ret;
cd80958d
DG
640 struct lttcomm_session_msg lsm;
641
642 if (!handle) {
643 return -1;
644 }
9f19cc17 645
cd80958d
DG
646 lsm.cmd_type = LTTNG_LIST_DOMAINS;
647
648 copy_string(lsm.session.name, handle->session_name,
649 sizeof(lsm.session.name));
650
651 ret = ask_sessiond(&lsm, (void**) domains);
9f19cc17
DG
652 if (ret < 0) {
653 return ret;
654 }
655
656 return ret / sizeof(struct lttng_domain);
657}
658
659/*
660 * List channels of a session
661 */
cd80958d
DG
662int lttng_list_channels(struct lttng_handle *handle,
663 struct lttng_channel **channels)
9f19cc17
DG
664{
665 int ret;
cd80958d
DG
666 struct lttcomm_session_msg lsm;
667
668 if (!handle) {
669 return -1;
670 }
671
672 lsm.cmd_type = LTTNG_LIST_CHANNELS;
673 copy_string(lsm.session.name, handle->session_name,
674 sizeof(lsm.session.name));
9f19cc17 675
cd80958d 676 copy_lttng_domain(&lsm.domain, &handle->domain);
9f19cc17 677
cd80958d 678 ret = ask_sessiond(&lsm, (void**) channels);
9f19cc17
DG
679 if (ret < 0) {
680 return ret;
681 }
682
683 return ret / sizeof(struct lttng_channel);
684}
685
686/*
687 * List events of a session channel.
688 */
cd80958d
DG
689int lttng_list_events(struct lttng_handle *handle,
690 const char *channel_name, struct lttng_event **events)
9f19cc17
DG
691{
692 int ret;
cd80958d 693 struct lttcomm_session_msg lsm;
9f19cc17 694
cd80958d
DG
695 if (!handle) {
696 return -1;
697 }
698
699 lsm.cmd_type = LTTNG_LIST_EVENTS;
700 copy_string(lsm.session.name, handle->session_name,
701 sizeof(lsm.session.name));
702 copy_string(lsm.u.list.channel_name, channel_name,
703 sizeof(lsm.u.list.channel_name));
704
705 copy_lttng_domain(&lsm.domain, &handle->domain);
9f19cc17 706
cd80958d 707 ret = ask_sessiond(&lsm, (void**) events);
9f19cc17
DG
708 if (ret < 0) {
709 return ret;
710 }
711
712 return ret / sizeof(struct lttng_event);
713}
714
fac6795d
DG
715/*
716 * lttng_set_tracing_group
717 *
718 * Set tracing group variable with name. This function
719 * allocate memory pointed by tracing_group.
720 */
721int lttng_set_tracing_group(const char *name)
722{
723 if (asprintf(&tracing_group, "%s", name) < 0) {
724 return -ENOMEM;
725 }
726
727 return 0;
728}
729
d0254c7c
MD
730/*
731 * lttng_calibrate
732 */
cd80958d 733int lttng_calibrate(struct lttng_handle *handle,
d0254c7c
MD
734 struct lttng_calibrate *calibrate)
735{
cd80958d 736 struct lttcomm_session_msg lsm;
d0254c7c 737
cd80958d
DG
738 if (!handle) {
739 return -1;
740 }
d0254c7c 741
cd80958d
DG
742 lsm.cmd_type = LTTNG_CALIBRATE;
743 copy_lttng_domain(&lsm.domain, &handle->domain);
d0254c7c 744
cd80958d
DG
745 memcpy(&lsm.u.calibrate, calibrate, sizeof(lsm.u.calibrate));
746
747 return ask_sessiond(&lsm, NULL);
d0254c7c
MD
748}
749
fac6795d
DG
750/*
751 * lttng_check_session_daemon
752 *
947308c4
DG
753 * Yes, return 1
754 * No, return 0
755 * Error, return negative value
fac6795d 756 */
947308c4 757int lttng_session_daemon_alive(void)
fac6795d
DG
758{
759 int ret;
760
761 ret = set_session_daemon_path();
762 if (ret < 0) {
947308c4 763 /* Error */
fac6795d
DG
764 return ret;
765 }
766
7d8234d9 767 /* If socket exist, we check if the daemon listens to connect. */
fac6795d
DG
768 ret = access(sessiond_sock_path, F_OK);
769 if (ret < 0) {
947308c4
DG
770 /* Not alive */
771 return 0;
fac6795d
DG
772 }
773
7d8234d9
MD
774 ret = lttcomm_connect_unix_sock(sessiond_sock_path);
775 if (ret < 0) {
776 /* Not alive */
777 return 0;
778 }
779 ret = lttcomm_close_unix_sock(ret);
780 if (ret < 0)
781 perror("lttcomm_close_unix_sock");
782
947308c4
DG
783 /* Is alive */
784 return 1;
fac6795d
DG
785}
786
787/*
788 * lib constructor
789 */
790static void __attribute__((constructor)) init()
791{
792 /* Set default session group */
64a23ac4 793 lttng_set_tracing_group(LTTNG_DEFAULT_TRACING_GROUP);
fac6795d 794}
This page took 0.100484 seconds and 4 git commands to generate.