Improve lttng.c usage()
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
... / ...
CommitLineData
1/*
2 * liblttngctl.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
7 *
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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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
21 */
22
23#define _GNU_SOURCE
24#include <grp.h>
25#include <errno.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <unistd.h>
30
31#include <common/common.h>
32#include <common/defaults.h>
33#include <common/sessiond-comm/sessiond-comm.h>
34#include <lttng/lttng.h>
35
36/* Socket to session daemon for communication */
37static int sessiond_socket;
38static char sessiond_sock_path[PATH_MAX];
39
40/* Variables */
41static char *tracing_group;
42static int connected;
43
44/*
45 * Copy string from src to dst and enforce null terminated byte.
46 */
47static void copy_string(char *dst, const char *src, size_t len)
48{
49 if (src && dst) {
50 strncpy(dst, src, len);
51 /* Enforce the NULL terminated byte */
52 dst[len - 1] = '\0';
53 } else if (dst) {
54 dst[0] = '\0';
55 }
56}
57
58/*
59 * Copy domain to lttcomm_session_msg domain.
60 *
61 * If domain is unknown, default domain will be the kernel.
62 */
63static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src)
64{
65 if (src && dst) {
66 switch (src->type) {
67 case LTTNG_DOMAIN_KERNEL:
68 case LTTNG_DOMAIN_UST:
69 /*
70 case LTTNG_DOMAIN_UST_EXEC_NAME:
71 case LTTNG_DOMAIN_UST_PID:
72 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
73 */
74 memcpy(dst, src, sizeof(struct lttng_domain));
75 break;
76 default:
77 dst->type = LTTNG_DOMAIN_KERNEL;
78 break;
79 }
80 }
81}
82
83/*
84 * Send lttcomm_session_msg to the session daemon.
85 *
86 * On success, return 0
87 * On error, return error code
88 */
89static int send_session_msg(struct lttcomm_session_msg *lsm)
90{
91 int ret;
92
93 if (!connected) {
94 ret = -ENOTCONN;
95 goto end;
96 }
97
98 ret = lttcomm_send_creds_unix_sock(sessiond_socket, lsm,
99 sizeof(struct lttcomm_session_msg));
100
101end:
102 return ret;
103}
104
105/*
106 * Receive data from the sessiond socket.
107 *
108 * On success, return 0
109 * On error, return recv() error code
110 */
111static int recv_data_sessiond(void *buf, size_t len)
112{
113 int ret;
114
115 if (!connected) {
116 ret = -ENOTCONN;
117 goto end;
118 }
119
120 ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len);
121
122end:
123 return ret;
124}
125
126/*
127 * Check if the specified group name exist.
128 *
129 * If yes return 1, else return -1.
130 */
131static int check_tracing_group(const char *grp_name)
132{
133 struct group *grp_tracing; /* no free(). See getgrnam(3) */
134 gid_t *grp_list;
135 int grp_list_size, grp_id, i;
136 int ret = -1;
137
138 /* Get GID of group 'tracing' */
139 grp_tracing = getgrnam(grp_name);
140 if (grp_tracing == NULL) {
141 /* NULL means not found also. getgrnam(3) */
142 if (errno != 0) {
143 perror("getgrnam");
144 }
145 goto end;
146 }
147
148 /* Get number of supplementary group IDs */
149 grp_list_size = getgroups(0, NULL);
150 if (grp_list_size < 0) {
151 perror("getgroups");
152 goto end;
153 }
154
155 /* Alloc group list of the right size */
156 grp_list = malloc(grp_list_size * sizeof(gid_t));
157 if (!grp_list) {
158 ret = -1;
159 goto end;
160 }
161 grp_id = getgroups(grp_list_size, grp_list);
162 if (grp_id < -1) {
163 perror("getgroups");
164 goto free_list;
165 }
166
167 for (i = 0; i < grp_list_size; i++) {
168 if (grp_list[i] == grp_tracing->gr_gid) {
169 ret = 1;
170 break;
171 }
172 }
173
174free_list:
175 free(grp_list);
176
177end:
178 return ret;
179}
180
181/*
182 * Try connect to session daemon with sock_path.
183 *
184 * Return 0 on success, else -1
185 */
186static int try_connect_sessiond(const char *sock_path)
187{
188 int ret;
189
190 /* If socket exist, we check if the daemon listens for connect. */
191 ret = access(sock_path, F_OK);
192 if (ret < 0) {
193 /* Not alive */
194 return -1;
195 }
196
197 ret = lttcomm_connect_unix_sock(sock_path);
198 if (ret < 0) {
199 /* Not alive */
200 return -1;
201 }
202
203 ret = lttcomm_close_unix_sock(ret);
204 if (ret < 0) {
205 perror("lttcomm_close_unix_sock");
206 }
207
208 return 0;
209}
210
211/*
212 * Set sessiond socket path by putting it in the global sessiond_sock_path
213 * variable.
214 */
215static int set_session_daemon_path(void)
216{
217 int ret;
218 int in_tgroup = 0; /* In tracing group */
219 uid_t uid;
220
221 uid = getuid();
222
223 if (uid != 0) {
224 /* Are we in the tracing group ? */
225 in_tgroup = check_tracing_group(tracing_group);
226 }
227
228 if (uid == 0) {
229 /* Root */
230 copy_string(sessiond_sock_path,
231 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
232 sizeof(sessiond_sock_path));
233 } else if (in_tgroup) {
234 /* Tracing group */
235 copy_string(sessiond_sock_path,
236 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
237 sizeof(sessiond_sock_path));
238
239 ret = try_connect_sessiond(sessiond_sock_path);
240 if (ret < 0) {
241 /* Global session daemon not available */
242 if (snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
243 DEFAULT_HOME_CLIENT_UNIX_SOCK,
244 getenv("HOME")) < 0) {
245 return -ENOMEM;
246 }
247 }
248 } else {
249 /* Not in tracing group and not root, default */
250 if (snprintf(sessiond_sock_path, PATH_MAX,
251 DEFAULT_HOME_CLIENT_UNIX_SOCK,
252 getenv("HOME")) < 0) {
253 return -ENOMEM;
254 }
255 }
256
257 return 0;
258}
259
260/*
261 * Connect to the LTTng session daemon.
262 *
263 * On success, return 0. On error, return -1.
264 */
265static int connect_sessiond(void)
266{
267 int ret;
268
269 ret = set_session_daemon_path();
270 if (ret < 0) {
271 return ret;
272 }
273
274 /* Connect to the sesssion daemon */
275 ret = lttcomm_connect_unix_sock(sessiond_sock_path);
276 if (ret < 0) {
277 return ret;
278 }
279
280 sessiond_socket = ret;
281 connected = 1;
282
283 return 0;
284}
285
286/*
287 * Clean disconnect the session daemon.
288 */
289static int disconnect_sessiond(void)
290{
291 int ret = 0;
292
293 if (connected) {
294 ret = lttcomm_close_unix_sock(sessiond_socket);
295 sessiond_socket = 0;
296 connected = 0;
297 }
298
299 return ret;
300}
301
302/*
303 * Ask the session daemon a specific command and put the data into buf.
304 *
305 * Return size of data (only payload, not header).
306 */
307static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
308{
309 int ret;
310 size_t size;
311 void *data = NULL;
312 struct lttcomm_lttng_msg llm;
313
314 ret = connect_sessiond();
315 if (ret < 0) {
316 goto end;
317 }
318
319 /* Send command to session daemon */
320 ret = send_session_msg(lsm);
321 if (ret < 0) {
322 goto end;
323 }
324
325 /* Get header from data transmission */
326 ret = recv_data_sessiond(&llm, sizeof(llm));
327 if (ret < 0) {
328 goto end;
329 }
330
331 /* Check error code if OK */
332 if (llm.ret_code != LTTCOMM_OK) {
333 ret = -llm.ret_code;
334 goto end;
335 }
336
337 size = llm.data_size;
338 if (size == 0) {
339 /* If client free with size 0 */
340 if (buf != NULL) {
341 *buf = NULL;
342 }
343 ret = 0;
344 goto end;
345 }
346
347 data = (void*) malloc(size);
348
349 /* Get payload data */
350 ret = recv_data_sessiond(data, size);
351 if (ret < 0) {
352 free(data);
353 goto end;
354 }
355
356 /*
357 * Extra protection not to dereference a NULL pointer. If buf is NULL at
358 * this point, an error is returned and data is freed.
359 */
360 if (buf == NULL) {
361 ret = -1;
362 free(data);
363 goto end;
364 }
365
366 *buf = data;
367 ret = size;
368
369end:
370 disconnect_sessiond();
371 return ret;
372}
373
374/*
375 * Create lttng handle and return pointer.
376 */
377struct lttng_handle *lttng_create_handle(const char *session_name,
378 struct lttng_domain *domain)
379{
380 struct lttng_handle *handle;
381
382 handle = malloc(sizeof(struct lttng_handle));
383 if (handle == NULL) {
384 perror("malloc handle");
385 goto end;
386 }
387
388 /* Copy session name */
389 copy_string(handle->session_name, session_name,
390 sizeof(handle->session_name));
391
392 /* Copy lttng domain */
393 copy_lttng_domain(&handle->domain, domain);
394
395end:
396 return handle;
397}
398
399/*
400 * Destroy handle by free(3) the pointer.
401 */
402void lttng_destroy_handle(struct lttng_handle *handle)
403{
404 if (handle) {
405 free(handle);
406 }
407}
408
409/*
410 * Register an outside consumer.
411 */
412int lttng_register_consumer(struct lttng_handle *handle,
413 const char *socket_path)
414{
415 struct lttcomm_session_msg lsm;
416
417 lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
418 copy_string(lsm.session.name, handle->session_name,
419 sizeof(lsm.session.name));
420 copy_lttng_domain(&lsm.domain, &handle->domain);
421
422 copy_string(lsm.u.reg.path, socket_path, sizeof(lsm.u.reg.path));
423
424 return ask_sessiond(&lsm, NULL);
425}
426
427/*
428 * Start tracing for all trace of the session.
429 */
430int lttng_start_tracing(const char *session_name)
431{
432 struct lttcomm_session_msg lsm;
433
434 if (session_name == NULL) {
435 return -1;
436 }
437
438 lsm.cmd_type = LTTNG_START_TRACE;
439
440 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
441
442 return ask_sessiond(&lsm, NULL);
443}
444
445/*
446 * Stop tracing for all trace of the session.
447 */
448int lttng_stop_tracing(const char *session_name)
449{
450 struct lttcomm_session_msg lsm;
451
452 if (session_name == NULL) {
453 return -1;
454 }
455
456 lsm.cmd_type = LTTNG_STOP_TRACE;
457
458 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
459
460 return ask_sessiond(&lsm, NULL);
461}
462
463/*
464 * Add context to event or/and channel.
465 */
466int lttng_add_context(struct lttng_handle *handle,
467 struct lttng_event_context *ctx, const char *event_name,
468 const char *channel_name)
469{
470 struct lttcomm_session_msg lsm;
471
472 /* Safety check. Both are mandatory */
473 if (handle == NULL || ctx == NULL) {
474 return -1;
475 }
476
477 lsm.cmd_type = LTTNG_ADD_CONTEXT;
478
479 /* Copy channel name */
480 copy_string(lsm.u.context.channel_name, channel_name,
481 sizeof(lsm.u.context.channel_name));
482 /* Copy event name */
483 copy_string(lsm.u.context.event_name, event_name,
484 sizeof(lsm.u.context.event_name));
485
486 copy_lttng_domain(&lsm.domain, &handle->domain);
487
488 memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
489
490 copy_string(lsm.session.name, handle->session_name,
491 sizeof(lsm.session.name));
492
493 return ask_sessiond(&lsm, NULL);
494}
495
496/*
497 * Enable event
498 */
499int lttng_enable_event(struct lttng_handle *handle,
500 struct lttng_event *ev, const char *channel_name)
501{
502 struct lttcomm_session_msg lsm;
503
504 if (handle == NULL || ev == NULL) {
505 return -1;
506 }
507
508 /* If no channel name, we put the default name */
509 if (channel_name == NULL) {
510 copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
511 sizeof(lsm.u.enable.channel_name));
512 } else {
513 copy_string(lsm.u.enable.channel_name, channel_name,
514 sizeof(lsm.u.enable.channel_name));
515 }
516
517 copy_lttng_domain(&lsm.domain, &handle->domain);
518
519 if (ev->name[0] != '\0') {
520 lsm.cmd_type = LTTNG_ENABLE_EVENT;
521 } else {
522 lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
523 }
524 memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
525
526 copy_string(lsm.session.name, handle->session_name,
527 sizeof(lsm.session.name));
528
529 return ask_sessiond(&lsm, NULL);
530}
531
532/*
533 * Disable event of a channel and domain.
534 */
535int lttng_disable_event(struct lttng_handle *handle, const char *name,
536 const char *channel_name)
537{
538 struct lttcomm_session_msg lsm;
539
540 if (handle == NULL) {
541 return -1;
542 }
543
544 if (channel_name) {
545 copy_string(lsm.u.disable.channel_name, channel_name,
546 sizeof(lsm.u.disable.channel_name));
547 } else {
548 copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME,
549 sizeof(lsm.u.disable.channel_name));
550 }
551
552 copy_lttng_domain(&lsm.domain, &handle->domain);
553
554 if (name != NULL) {
555 copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name));
556 lsm.cmd_type = LTTNG_DISABLE_EVENT;
557 } else {
558 lsm.cmd_type = LTTNG_DISABLE_ALL_EVENT;
559 }
560
561 copy_string(lsm.session.name, handle->session_name,
562 sizeof(lsm.session.name));
563
564 return ask_sessiond(&lsm, NULL);
565}
566
567/*
568 * Enable channel per domain
569 */
570int lttng_enable_channel(struct lttng_handle *handle,
571 struct lttng_channel *chan)
572{
573 struct lttcomm_session_msg lsm;
574
575 /*
576 * NULL arguments are forbidden. No default values.
577 */
578 if (handle == NULL || chan == NULL) {
579 return -1;
580 }
581
582 memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
583
584 lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
585
586 copy_lttng_domain(&lsm.domain, &handle->domain);
587
588 copy_string(lsm.session.name, handle->session_name,
589 sizeof(lsm.session.name));
590
591 return ask_sessiond(&lsm, NULL);
592}
593
594/*
595 * All tracing will be stopped for registered events of the channel.
596 */
597int lttng_disable_channel(struct lttng_handle *handle, const char *name)
598{
599 struct lttcomm_session_msg lsm;
600
601 /* Safety check. Both are mandatory */
602 if (handle == NULL || name == NULL) {
603 return -1;
604 }
605
606 lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
607
608 copy_string(lsm.u.disable.channel_name, name,
609 sizeof(lsm.u.disable.channel_name));
610
611 copy_lttng_domain(&lsm.domain, &handle->domain);
612
613 copy_string(lsm.session.name, handle->session_name,
614 sizeof(lsm.session.name));
615
616 return ask_sessiond(&lsm, NULL);
617}
618
619/*
620 * List all available tracepoints of domain.
621 *
622 * Return the size (bytes) of the list and set the events array.
623 * On error, return negative value.
624 */
625int lttng_list_tracepoints(struct lttng_handle *handle,
626 struct lttng_event **events)
627{
628 int ret;
629 struct lttcomm_session_msg lsm;
630
631 if (handle == NULL) {
632 return -1;
633 }
634
635 lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
636 copy_lttng_domain(&lsm.domain, &handle->domain);
637
638 ret = ask_sessiond(&lsm, (void **) events);
639 if (ret < 0) {
640 return ret;
641 }
642
643 return ret / sizeof(struct lttng_event);
644}
645
646/*
647 * Return a human readable string of code
648 */
649const char *lttng_strerror(int code)
650{
651 if (code > -LTTCOMM_OK) {
652 return "Ended with errors";
653 }
654
655 return lttcomm_get_readable_code(code);
656}
657
658/*
659 * Create a brand new session using name.
660 */
661int lttng_create_session(const char *name, const char *path)
662{
663 struct lttcomm_session_msg lsm;
664
665 lsm.cmd_type = LTTNG_CREATE_SESSION;
666 copy_string(lsm.session.name, name, sizeof(lsm.session.name));
667 copy_string(lsm.session.path, path, sizeof(lsm.session.path));
668
669 return ask_sessiond(&lsm, NULL);
670}
671
672/*
673 * Destroy session using name.
674 */
675int lttng_destroy_session(const char *session_name)
676{
677 struct lttcomm_session_msg lsm;
678
679 if (session_name == NULL) {
680 return -1;
681 }
682
683 lsm.cmd_type = LTTNG_DESTROY_SESSION;
684
685 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
686
687 return ask_sessiond(&lsm, NULL);
688}
689
690/*
691 * Ask the session daemon for all available sessions.
692 *
693 * Return number of session.
694 * On error, return negative value.
695 */
696int lttng_list_sessions(struct lttng_session **sessions)
697{
698 int ret;
699 struct lttcomm_session_msg lsm;
700
701 lsm.cmd_type = LTTNG_LIST_SESSIONS;
702 ret = ask_sessiond(&lsm, (void**) sessions);
703 if (ret < 0) {
704 return ret;
705 }
706
707 return ret / sizeof(struct lttng_session);
708}
709
710/*
711 * List domain of a session.
712 */
713int lttng_list_domains(const char *session_name,
714 struct lttng_domain **domains)
715{
716 int ret;
717 struct lttcomm_session_msg lsm;
718
719 if (session_name == NULL) {
720 return -1;
721 }
722
723 lsm.cmd_type = LTTNG_LIST_DOMAINS;
724
725 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
726
727 ret = ask_sessiond(&lsm, (void**) domains);
728 if (ret < 0) {
729 return ret;
730 }
731
732 return ret / sizeof(struct lttng_domain);
733}
734
735/*
736 * List channels of a session
737 */
738int lttng_list_channels(struct lttng_handle *handle,
739 struct lttng_channel **channels)
740{
741 int ret;
742 struct lttcomm_session_msg lsm;
743
744 if (handle == NULL) {
745 return -1;
746 }
747
748 lsm.cmd_type = LTTNG_LIST_CHANNELS;
749 copy_string(lsm.session.name, handle->session_name,
750 sizeof(lsm.session.name));
751
752 copy_lttng_domain(&lsm.domain, &handle->domain);
753
754 ret = ask_sessiond(&lsm, (void**) channels);
755 if (ret < 0) {
756 return ret;
757 }
758
759 return ret / sizeof(struct lttng_channel);
760}
761
762/*
763 * List events of a session channel.
764 */
765int lttng_list_events(struct lttng_handle *handle,
766 const char *channel_name, struct lttng_event **events)
767{
768 int ret;
769 struct lttcomm_session_msg lsm;
770
771 /* Safety check. An handle and channel name are mandatory */
772 if (handle == NULL || channel_name == NULL) {
773 return -1;
774 }
775
776 lsm.cmd_type = LTTNG_LIST_EVENTS;
777 copy_string(lsm.session.name, handle->session_name,
778 sizeof(lsm.session.name));
779 copy_string(lsm.u.list.channel_name, channel_name,
780 sizeof(lsm.u.list.channel_name));
781
782 copy_lttng_domain(&lsm.domain, &handle->domain);
783
784 ret = ask_sessiond(&lsm, (void**) events);
785 if (ret < 0) {
786 return ret;
787 }
788
789 return ret / sizeof(struct lttng_event);
790}
791
792/*
793 * Set tracing group variable with name. This function allocate memory pointed
794 * by tracing_group.
795 */
796int lttng_set_tracing_group(const char *name)
797{
798 if (name == NULL) {
799 return -1;
800 }
801
802 if (asprintf(&tracing_group, "%s", name) < 0) {
803 return -ENOMEM;
804 }
805
806 return 0;
807}
808
809/*
810 * lttng_calibrate
811 */
812int lttng_calibrate(struct lttng_handle *handle,
813 struct lttng_calibrate *calibrate)
814{
815 struct lttcomm_session_msg lsm;
816
817 /* Safety check. NULL pointer are forbidden */
818 if (handle == NULL || calibrate == NULL) {
819 return -1;
820 }
821
822 lsm.cmd_type = LTTNG_CALIBRATE;
823 copy_lttng_domain(&lsm.domain, &handle->domain);
824
825 memcpy(&lsm.u.calibrate, calibrate, sizeof(lsm.u.calibrate));
826
827 return ask_sessiond(&lsm, NULL);
828}
829
830/*
831 * Set default channel attributes.
832 */
833void lttng_channel_set_default_attr(struct lttng_domain *domain,
834 struct lttng_channel_attr *attr)
835{
836 /* Safety check */
837 if (attr == NULL || domain == NULL) {
838 return;
839 }
840
841 switch (domain->type) {
842 case LTTNG_DOMAIN_KERNEL:
843 attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
844 attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
845 attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
846
847 attr->subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
848 attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
849 attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
850 break;
851 case LTTNG_DOMAIN_UST:
852#if 0
853 case LTTNG_DOMAIN_UST_EXEC_NAME:
854 case LTTNG_DOMAIN_UST_PID:
855 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
856#endif
857 attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
858 attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
859 attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
860
861 attr->subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
862 attr->num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
863 attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
864 break;
865 default:
866 /* Default behavior */
867 memset(attr, 0, sizeof(struct lttng_channel_attr));
868 break;
869 }
870}
871
872/*
873 * Check if session daemon is alive.
874 *
875 * Return 1 if alive or 0 if not.
876 * On error return -1
877 */
878int lttng_session_daemon_alive(void)
879{
880 int ret;
881
882 ret = set_session_daemon_path();
883 if (ret < 0) {
884 /* Error */
885 return ret;
886 }
887
888 if (strlen(sessiond_sock_path) == 0) {
889 /* No socket path set. Weird error */
890 return -1;
891 }
892
893 ret = try_connect_sessiond(sessiond_sock_path);
894 if (ret < 0) {
895 /* Not alive */
896 return 0;
897 }
898
899 /* Is alive */
900 return 1;
901}
902
903/*
904 * lib constructor
905 */
906static void __attribute__((constructor)) init()
907{
908 /* Set default session group */
909 lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
910}
This page took 0.026589 seconds and 5 git commands to generate.