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