Catching up on misc. string and comment fixes
[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) or a negative error code.
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 *
466 * Returns the size of the returned payload data or a negative error code.
467 */
468int lttng_add_context(struct lttng_handle *handle,
469 struct lttng_event_context *ctx, const char *event_name,
470 const char *channel_name)
471{
472 struct lttcomm_session_msg lsm;
473
474 /* Safety check. Both are mandatory */
475 if (handle == NULL || ctx == NULL) {
476 return -1;
477 }
478
479 lsm.cmd_type = LTTNG_ADD_CONTEXT;
480
481 /* Copy channel name */
482 copy_string(lsm.u.context.channel_name, channel_name,
483 sizeof(lsm.u.context.channel_name));
484 /* Copy event name */
485 copy_string(lsm.u.context.event_name, event_name,
486 sizeof(lsm.u.context.event_name));
487
488 copy_lttng_domain(&lsm.domain, &handle->domain);
489
490 memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
491
492 copy_string(lsm.session.name, handle->session_name,
493 sizeof(lsm.session.name));
494
495 return ask_sessiond(&lsm, NULL);
496}
497
498/*
499 * Enable event
500 */
501int lttng_enable_event(struct lttng_handle *handle,
502 struct lttng_event *ev, const char *channel_name)
503{
504 struct lttcomm_session_msg lsm;
505
506 if (handle == NULL || ev == NULL) {
507 return -1;
508 }
509
510 /* If no channel name, we put the default name */
511 if (channel_name == NULL) {
512 copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
513 sizeof(lsm.u.enable.channel_name));
514 } else {
515 copy_string(lsm.u.enable.channel_name, channel_name,
516 sizeof(lsm.u.enable.channel_name));
517 }
518
519 copy_lttng_domain(&lsm.domain, &handle->domain);
520
521 if (ev->name[0] != '\0') {
522 lsm.cmd_type = LTTNG_ENABLE_EVENT;
523 } else {
524 lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
525 }
526 memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
527
528 copy_string(lsm.session.name, handle->session_name,
529 sizeof(lsm.session.name));
530
531 return ask_sessiond(&lsm, NULL);
532}
533
534/*
535 * Disable event of a channel and domain.
536 */
537int lttng_disable_event(struct lttng_handle *handle, const char *name,
538 const char *channel_name)
539{
540 struct lttcomm_session_msg lsm;
541
542 if (handle == NULL) {
543 return -1;
544 }
545
546 if (channel_name) {
547 copy_string(lsm.u.disable.channel_name, channel_name,
548 sizeof(lsm.u.disable.channel_name));
549 } else {
550 copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME,
551 sizeof(lsm.u.disable.channel_name));
552 }
553
554 copy_lttng_domain(&lsm.domain, &handle->domain);
555
556 if (name != NULL) {
557 copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name));
558 lsm.cmd_type = LTTNG_DISABLE_EVENT;
559 } else {
560 lsm.cmd_type = LTTNG_DISABLE_ALL_EVENT;
561 }
562
563 copy_string(lsm.session.name, handle->session_name,
564 sizeof(lsm.session.name));
565
566 return ask_sessiond(&lsm, NULL);
567}
568
569/*
570 * Enable channel per domain
571 */
572int lttng_enable_channel(struct lttng_handle *handle,
573 struct lttng_channel *chan)
574{
575 struct lttcomm_session_msg lsm;
576
577 /*
578 * NULL arguments are forbidden. No default values.
579 */
580 if (handle == NULL || chan == NULL) {
581 return -1;
582 }
583
584 memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
585
586 lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
587
588 copy_lttng_domain(&lsm.domain, &handle->domain);
589
590 copy_string(lsm.session.name, handle->session_name,
591 sizeof(lsm.session.name));
592
593 return ask_sessiond(&lsm, NULL);
594}
595
596/*
597 * All tracing will be stopped for registered events of the channel.
598 */
599int lttng_disable_channel(struct lttng_handle *handle, const char *name)
600{
601 struct lttcomm_session_msg lsm;
602
603 /* Safety check. Both are mandatory */
604 if (handle == NULL || name == NULL) {
605 return -1;
606 }
607
608 lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
609
610 copy_string(lsm.u.disable.channel_name, name,
611 sizeof(lsm.u.disable.channel_name));
612
613 copy_lttng_domain(&lsm.domain, &handle->domain);
614
615 copy_string(lsm.session.name, handle->session_name,
616 sizeof(lsm.session.name));
617
618 return ask_sessiond(&lsm, NULL);
619}
620
621/*
622 * List all available tracepoints of domain.
623 *
624 * Return the size (bytes) of the list and set the events array.
625 * On error, return negative value.
626 */
627int lttng_list_tracepoints(struct lttng_handle *handle,
628 struct lttng_event **events)
629{
630 int ret;
631 struct lttcomm_session_msg lsm;
632
633 if (handle == NULL) {
634 return -1;
635 }
636
637 lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
638 copy_lttng_domain(&lsm.domain, &handle->domain);
639
640 ret = ask_sessiond(&lsm, (void **) events);
641 if (ret < 0) {
642 return ret;
643 }
644
645 return ret / sizeof(struct lttng_event);
646}
647
648/*
649 * Return a human readable string of code
650 */
651const char *lttng_strerror(int code)
652{
653 if (code > -LTTCOMM_OK) {
654 return "Ended with errors";
655 }
656
657 return lttcomm_get_readable_code(code);
658}
659
660/*
661 * Create a brand new session using name.
662 */
663int lttng_create_session(const char *name, const char *path)
664{
665 struct lttcomm_session_msg lsm;
666
667 lsm.cmd_type = LTTNG_CREATE_SESSION;
668 copy_string(lsm.session.name, name, sizeof(lsm.session.name));
669 copy_string(lsm.session.path, path, sizeof(lsm.session.path));
670
671 return ask_sessiond(&lsm, NULL);
672}
673
674/*
675 * Destroy session using name.
676 */
677int lttng_destroy_session(const char *session_name)
678{
679 struct lttcomm_session_msg lsm;
680
681 if (session_name == NULL) {
682 return -1;
683 }
684
685 lsm.cmd_type = LTTNG_DESTROY_SESSION;
686
687 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
688
689 return ask_sessiond(&lsm, NULL);
690}
691
692/*
693 * Ask the session daemon for all available sessions.
694 *
695 * Return number of session.
696 * On error, return negative value.
697 */
698int lttng_list_sessions(struct lttng_session **sessions)
699{
700 int ret;
701 struct lttcomm_session_msg lsm;
702
703 lsm.cmd_type = LTTNG_LIST_SESSIONS;
704 ret = ask_sessiond(&lsm, (void**) sessions);
705 if (ret < 0) {
706 return ret;
707 }
708
709 return ret / sizeof(struct lttng_session);
710}
711
712/*
713 * List domain of a session.
714 */
715int lttng_list_domains(const char *session_name,
716 struct lttng_domain **domains)
717{
718 int ret;
719 struct lttcomm_session_msg lsm;
720
721 if (session_name == NULL) {
722 return -1;
723 }
724
725 lsm.cmd_type = LTTNG_LIST_DOMAINS;
726
727 copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
728
729 ret = ask_sessiond(&lsm, (void**) domains);
730 if (ret < 0) {
731 return ret;
732 }
733
734 return ret / sizeof(struct lttng_domain);
735}
736
737/*
738 * List channels of a session
739 */
740int lttng_list_channels(struct lttng_handle *handle,
741 struct lttng_channel **channels)
742{
743 int ret;
744 struct lttcomm_session_msg lsm;
745
746 if (handle == NULL) {
747 return -1;
748 }
749
750 lsm.cmd_type = LTTNG_LIST_CHANNELS;
751 copy_string(lsm.session.name, handle->session_name,
752 sizeof(lsm.session.name));
753
754 copy_lttng_domain(&lsm.domain, &handle->domain);
755
756 ret = ask_sessiond(&lsm, (void**) channels);
757 if (ret < 0) {
758 return ret;
759 }
760
761 return ret / sizeof(struct lttng_channel);
762}
763
764/*
765 * List events of a session channel.
766 */
767int lttng_list_events(struct lttng_handle *handle,
768 const char *channel_name, struct lttng_event **events)
769{
770 int ret;
771 struct lttcomm_session_msg lsm;
772
773 /* Safety check. An handle and channel name are mandatory */
774 if (handle == NULL || channel_name == NULL) {
775 return -1;
776 }
777
778 lsm.cmd_type = LTTNG_LIST_EVENTS;
779 copy_string(lsm.session.name, handle->session_name,
780 sizeof(lsm.session.name));
781 copy_string(lsm.u.list.channel_name, channel_name,
782 sizeof(lsm.u.list.channel_name));
783
784 copy_lttng_domain(&lsm.domain, &handle->domain);
785
786 ret = ask_sessiond(&lsm, (void**) events);
787 if (ret < 0) {
788 return ret;
789 }
790
791 return ret / sizeof(struct lttng_event);
792}
793
794/*
795 * Set tracing group variable with name. This function allocate memory pointed
796 * by tracing_group.
797 */
798int lttng_set_tracing_group(const char *name)
799{
800 if (name == NULL) {
801 return -1;
802 }
803
804 if (asprintf(&tracing_group, "%s", name) < 0) {
805 return -ENOMEM;
806 }
807
808 return 0;
809}
810
811/*
812 * Returns size of returned session payload data or a negative error code.
813 */
814int lttng_calibrate(struct lttng_handle *handle,
815 struct lttng_calibrate *calibrate)
816{
817 struct lttcomm_session_msg lsm;
818
819 /* Safety check. NULL pointer are forbidden */
820 if (handle == NULL || calibrate == NULL) {
821 return -1;
822 }
823
824 lsm.cmd_type = LTTNG_CALIBRATE;
825 copy_lttng_domain(&lsm.domain, &handle->domain);
826
827 memcpy(&lsm.u.calibrate, calibrate, sizeof(lsm.u.calibrate));
828
829 return ask_sessiond(&lsm, NULL);
830}
831
832/*
833 * Set default channel attributes.
834 */
835void lttng_channel_set_default_attr(struct lttng_domain *domain,
836 struct lttng_channel_attr *attr)
837{
838 /* Safety check */
839 if (attr == NULL || domain == NULL) {
840 return;
841 }
842
843 switch (domain->type) {
844 case LTTNG_DOMAIN_KERNEL:
845 attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
846 attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
847 attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
848
849 attr->subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
850 attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
851 attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
852 break;
853 case LTTNG_DOMAIN_UST:
854#if 0
855 case LTTNG_DOMAIN_UST_EXEC_NAME:
856 case LTTNG_DOMAIN_UST_PID:
857 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
858#endif
859 attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
860 attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
861 attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
862
863 attr->subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
864 attr->num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
865 attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
866 break;
867 default:
868 /* Default behavior */
869 memset(attr, 0, sizeof(struct lttng_channel_attr));
870 break;
871 }
872}
873
874/*
875 * Check if session daemon is alive.
876 *
877 * Return 1 if alive or 0 if not.
878 * On error return -1
879 */
880int lttng_session_daemon_alive(void)
881{
882 int ret;
883
884 ret = set_session_daemon_path();
885 if (ret < 0) {
886 /* Error */
887 return ret;
888 }
889
890 if (strlen(sessiond_sock_path) == 0) {
891 /* No socket path set. Weird error */
892 return -1;
893 }
894
895 ret = try_connect_sessiond(sessiond_sock_path);
896 if (ret < 0) {
897 /* Not alive */
898 return 0;
899 }
900
901 /* Is alive */
902 return 1;
903}
904
905/*
906 * lib constructor
907 */
908static void __attribute__((constructor)) init()
909{
910 /* Set default session group */
911 lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
912}
This page took 0.026508 seconds and 5 git commands to generate.