4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <common/common.h>
31 #include <common/defaults.h>
32 #include <common/sessiond-comm/sessiond-comm.h>
33 #include <lttng/lttng.h>
35 /* Socket to session daemon for communication */
36 static int sessiond_socket
;
37 static char sessiond_sock_path
[PATH_MAX
];
40 static char *tracing_group
;
46 * Those two variables are used by error.h to silent or control the verbosity of
47 * error message. They are global to the library so application linking with it
48 * are able to compile correctly and also control verbosity of the library.
50 * Note that it is *not* possible to silent ERR() and PERROR() macros.
53 int lttng_opt_verbose
;
56 * Copy string from src to dst and enforce null terminated byte.
58 static void copy_string(char *dst
, const char *src
, size_t len
)
61 strncpy(dst
, src
, len
);
62 /* Enforce the NULL terminated byte */
70 * Copy domain to lttcomm_session_msg domain.
72 * If domain is unknown, default domain will be the kernel.
74 static void copy_lttng_domain(struct lttng_domain
*dst
, struct lttng_domain
*src
)
78 case LTTNG_DOMAIN_KERNEL
:
79 case LTTNG_DOMAIN_UST
:
81 case LTTNG_DOMAIN_UST_EXEC_NAME:
82 case LTTNG_DOMAIN_UST_PID:
83 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
85 memcpy(dst
, src
, sizeof(struct lttng_domain
));
88 memset(dst
, 0, sizeof(struct lttng_domain
));
89 dst
->type
= LTTNG_DOMAIN_KERNEL
;
96 * Send lttcomm_session_msg to the session daemon.
98 * On success, returns the number of bytes sent (>=0)
99 * On error, returns -1
101 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
110 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
111 sizeof(struct lttcomm_session_msg
));
118 * Receive data from the sessiond socket.
120 * On success, returns the number of bytes received (>=0)
121 * On error, returns -1 (recvmsg() error) or -ENOTCONN
123 static int recv_data_sessiond(void *buf
, size_t len
)
132 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
139 * Check if we are in the specified group.
141 * If yes return 1, else return -1.
143 static int check_tracing_group(const char *grp_name
)
145 struct group
*grp_tracing
; /* no free(). See getgrnam(3) */
147 int grp_list_size
, grp_id
, i
;
150 /* Get GID of group 'tracing' */
151 grp_tracing
= getgrnam(grp_name
);
153 /* If grp_tracing is NULL, the group does not exist. */
157 /* Get number of supplementary group IDs */
158 grp_list_size
= getgroups(0, NULL
);
159 if (grp_list_size
< 0) {
164 /* Alloc group list of the right size */
165 grp_list
= malloc(grp_list_size
* sizeof(gid_t
));
170 grp_id
= getgroups(grp_list_size
, grp_list
);
176 for (i
= 0; i
< grp_list_size
; i
++) {
177 if (grp_list
[i
] == grp_tracing
->gr_gid
) {
191 * Try connect to session daemon with sock_path.
193 * Return 0 on success, else -1
195 static int try_connect_sessiond(const char *sock_path
)
199 /* If socket exist, we check if the daemon listens for connect. */
200 ret
= access(sock_path
, F_OK
);
206 ret
= lttcomm_connect_unix_sock(sock_path
);
212 ret
= lttcomm_close_unix_sock(ret
);
214 perror("lttcomm_close_unix_sock");
221 * Set sessiond socket path by putting it in the global
222 * sessiond_sock_path variable.
223 * Returns 0 on success,
224 * -ENOMEM on failure (the sessiond socket path is somehow too long)
226 static int set_session_daemon_path(void)
229 int in_tgroup
= 0; /* In tracing group */
235 /* Are we in the tracing group ? */
236 in_tgroup
= check_tracing_group(tracing_group
);
239 if ((uid
== 0) || in_tgroup
) {
240 copy_string(sessiond_sock_path
, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
,
241 sizeof(sessiond_sock_path
));
247 ret
= try_connect_sessiond(sessiond_sock_path
);
251 /* Global session daemon not available... */
253 /* ...or not in tracing group (and not root), default */
256 * With GNU C < 2.1, snprintf returns -1 if the target buffer is too small;
257 * With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
259 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
260 DEFAULT_HOME_CLIENT_UNIX_SOCK
, getenv("HOME"));
261 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
270 * Connect to the LTTng session daemon.
272 * On success, return 0. On error, return -1.
274 static int connect_sessiond(void)
278 ret
= set_session_daemon_path();
280 return -1; /* set_session_daemon_path() returns -ENOMEM */
283 /* Connect to the sesssion daemon */
284 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
289 sessiond_socket
= ret
;
296 * Clean disconnect from the session daemon.
297 * On success, return 0. On error, return -1.
299 static int disconnect_sessiond(void)
304 ret
= lttcomm_close_unix_sock(sessiond_socket
);
313 * Ask the session daemon a specific command and put the data into buf.
315 * Return size of data (only payload, not header) or a negative error code.
317 static int ask_sessiond(struct lttcomm_session_msg
*lsm
, void **buf
)
322 struct lttcomm_lttng_msg llm
;
324 ret
= connect_sessiond();
329 /* Send command to session daemon */
330 ret
= send_session_msg(lsm
);
335 /* Get header from data transmission */
336 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
341 /* Check error code if OK */
342 if (llm
.ret_code
!= LTTCOMM_OK
) {
347 size
= llm
.data_size
;
349 /* If client free with size 0 */
357 data
= (void*) malloc(size
);
359 /* Get payload data */
360 ret
= recv_data_sessiond(data
, size
);
367 * Extra protection not to dereference a NULL pointer. If buf is NULL at
368 * this point, an error is returned and data is freed.
380 disconnect_sessiond();
385 * Create lttng handle and return pointer.
386 * The returned pointer will be NULL in case of malloc() error.
388 struct lttng_handle
*lttng_create_handle(const char *session_name
,
389 struct lttng_domain
*domain
)
391 struct lttng_handle
*handle
;
393 handle
= malloc(sizeof(struct lttng_handle
));
394 if (handle
== NULL
) {
395 perror("malloc handle");
399 /* Copy session name */
400 copy_string(handle
->session_name
, session_name
,
401 sizeof(handle
->session_name
));
403 /* Copy lttng domain */
404 copy_lttng_domain(&handle
->domain
, domain
);
411 * Destroy handle by free(3) the pointer.
413 void lttng_destroy_handle(struct lttng_handle
*handle
)
421 * Register an outside consumer.
422 * Returns size of returned session payload data or a negative error code.
424 int lttng_register_consumer(struct lttng_handle
*handle
,
425 const char *socket_path
)
427 struct lttcomm_session_msg lsm
;
429 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
430 copy_string(lsm
.session
.name
, handle
->session_name
,
431 sizeof(lsm
.session
.name
));
432 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
434 copy_string(lsm
.u
.reg
.path
, socket_path
, sizeof(lsm
.u
.reg
.path
));
436 return ask_sessiond(&lsm
, NULL
);
440 * Start tracing for all traces of the session.
441 * Returns size of returned session payload data or a negative error code.
443 int lttng_start_tracing(const char *session_name
)
445 struct lttcomm_session_msg lsm
;
447 if (session_name
== NULL
) {
451 lsm
.cmd_type
= LTTNG_START_TRACE
;
453 copy_string(lsm
.session
.name
, session_name
, sizeof(lsm
.session
.name
));
455 return ask_sessiond(&lsm
, NULL
);
459 * Stop tracing for all traces of the session.
460 * Returns size of returned session payload data or a negative error code.
462 int lttng_stop_tracing(const char *session_name
)
464 struct lttcomm_session_msg lsm
;
466 if (session_name
== NULL
) {
470 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
472 copy_string(lsm
.session
.name
, session_name
, sizeof(lsm
.session
.name
));
474 return ask_sessiond(&lsm
, NULL
);
478 * Add context to event and/or channel.
479 * If event_name is NULL, the context is applied to all events of the channel.
480 * If channel_name is NULL, a lookup of the event's channel is done.
481 * If both are NULL, the context is applied to all events of all channels.
483 * Returns the size of the returned payload data or a negative error code.
485 int lttng_add_context(struct lttng_handle
*handle
,
486 struct lttng_event_context
*ctx
, const char *event_name
,
487 const char *channel_name
)
489 struct lttcomm_session_msg lsm
;
491 /* Safety check. Both are mandatory */
492 if (handle
== NULL
|| ctx
== NULL
) {
496 memset(&lsm
, 0, sizeof(lsm
));
498 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
500 /* Copy channel name */
501 copy_string(lsm
.u
.context
.channel_name
, channel_name
,
502 sizeof(lsm
.u
.context
.channel_name
));
503 /* Copy event name */
504 copy_string(lsm
.u
.context
.event_name
, event_name
,
505 sizeof(lsm
.u
.context
.event_name
));
507 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
509 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
511 copy_string(lsm
.session
.name
, handle
->session_name
,
512 sizeof(lsm
.session
.name
));
514 return ask_sessiond(&lsm
, NULL
);
518 * Enable event(s) for a channel.
519 * If no event name is specified, all events are enabled.
520 * If no channel name is specified, the default 'channel0' is used.
521 * Returns size of returned session payload data or a negative error code.
523 int lttng_enable_event(struct lttng_handle
*handle
,
524 struct lttng_event
*ev
, const char *channel_name
)
526 struct lttcomm_session_msg lsm
;
528 if (handle
== NULL
|| ev
== NULL
) {
532 memset(&lsm
, 0, sizeof(lsm
));
534 /* If no channel name, we put the default name */
535 if (channel_name
== NULL
) {
536 copy_string(lsm
.u
.enable
.channel_name
, DEFAULT_CHANNEL_NAME
,
537 sizeof(lsm
.u
.enable
.channel_name
));
539 copy_string(lsm
.u
.enable
.channel_name
, channel_name
,
540 sizeof(lsm
.u
.enable
.channel_name
));
543 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
545 if (ev
->name
[0] != '\0') {
546 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
548 lsm
.cmd_type
= LTTNG_ENABLE_ALL_EVENT
;
550 memcpy(&lsm
.u
.enable
.event
, ev
, sizeof(lsm
.u
.enable
.event
));
552 copy_string(lsm
.session
.name
, handle
->session_name
,
553 sizeof(lsm
.session
.name
));
555 return ask_sessiond(&lsm
, NULL
);
559 * Disable event(s) of a channel and domain.
560 * If no event name is specified, all events are disabled.
561 * If no channel name is specified, the default 'channel0' is used.
562 * Returns size of returned session payload data or a negative error code.
564 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
565 const char *channel_name
)
567 struct lttcomm_session_msg lsm
;
569 if (handle
== NULL
) {
573 memset(&lsm
, 0, sizeof(lsm
));
576 copy_string(lsm
.u
.disable
.channel_name
, channel_name
,
577 sizeof(lsm
.u
.disable
.channel_name
));
579 copy_string(lsm
.u
.disable
.channel_name
, DEFAULT_CHANNEL_NAME
,
580 sizeof(lsm
.u
.disable
.channel_name
));
583 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
586 copy_string(lsm
.u
.disable
.name
, name
, sizeof(lsm
.u
.disable
.name
));
587 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
589 lsm
.cmd_type
= LTTNG_DISABLE_ALL_EVENT
;
592 copy_string(lsm
.session
.name
, handle
->session_name
,
593 sizeof(lsm
.session
.name
));
595 return ask_sessiond(&lsm
, NULL
);
599 * Enable channel per domain
600 * Returns size of returned session payload data or a negative error code.
602 int lttng_enable_channel(struct lttng_handle
*handle
,
603 struct lttng_channel
*chan
)
605 struct lttcomm_session_msg lsm
;
608 * NULL arguments are forbidden. No default values.
610 if (handle
== NULL
|| chan
== NULL
) {
614 memset(&lsm
, 0, sizeof(lsm
));
616 memcpy(&lsm
.u
.channel
.chan
, chan
, sizeof(lsm
.u
.channel
.chan
));
618 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
620 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
622 copy_string(lsm
.session
.name
, handle
->session_name
,
623 sizeof(lsm
.session
.name
));
625 return ask_sessiond(&lsm
, NULL
);
629 * All tracing will be stopped for registered events of the channel.
630 * Returns size of returned session payload data or a negative error code.
632 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
634 struct lttcomm_session_msg lsm
;
636 /* Safety check. Both are mandatory */
637 if (handle
== NULL
|| name
== NULL
) {
641 memset(&lsm
, 0, sizeof(lsm
));
643 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
645 copy_string(lsm
.u
.disable
.channel_name
, name
,
646 sizeof(lsm
.u
.disable
.channel_name
));
648 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
650 copy_string(lsm
.session
.name
, handle
->session_name
,
651 sizeof(lsm
.session
.name
));
653 return ask_sessiond(&lsm
, NULL
);
657 * Lists all available tracepoints of domain.
658 * Sets the contents of the events array.
659 * Returns the number of lttng_event entries in events;
660 * on error, returns a negative value.
662 int lttng_list_tracepoints(struct lttng_handle
*handle
,
663 struct lttng_event
**events
)
666 struct lttcomm_session_msg lsm
;
668 if (handle
== NULL
) {
672 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
673 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
675 ret
= ask_sessiond(&lsm
, (void **) events
);
680 return ret
/ sizeof(struct lttng_event
);
684 * Lists all available tracepoint fields of domain.
685 * Sets the contents of the event field array.
686 * Returns the number of lttng_event_field entries in events;
687 * on error, returns a negative value.
689 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
690 struct lttng_event_field
**fields
)
693 struct lttcomm_session_msg lsm
;
695 if (handle
== NULL
) {
699 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
700 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
702 ret
= ask_sessiond(&lsm
, (void **) fields
);
707 return ret
/ sizeof(struct lttng_event_field
);
711 * Returns a human readable string describing
712 * the error code (a negative value).
714 const char *lttng_strerror(int code
)
716 /* lttcomm error codes range from -LTTCOMM_OK down to -LTTCOMM_NR */
717 if (code
> -LTTCOMM_OK
) {
718 return "Ended with errors";
721 return lttcomm_get_readable_code(code
);
725 * Create a brand new session using name and path.
726 * Returns size of returned session payload data or a negative error code.
728 int lttng_create_session(const char *name
, const char *path
)
730 struct lttcomm_session_msg lsm
;
732 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
733 copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
734 copy_string(lsm
.session
.path
, path
, sizeof(lsm
.session
.path
));
736 return ask_sessiond(&lsm
, NULL
);
740 * Create a new tracing session using a name, URIs and a consumer enable flag.
742 int lttng_create_session_uri(const char *name
, struct lttng_uri
*ctrl_uri
,
743 struct lttng_uri
*data_uri
, unsigned int enable_consumer
)
745 struct lttcomm_session_msg lsm
;
747 /* Name and ctrl_uri are mandatory */
748 if (name
== NULL
|| ctrl_uri
== NULL
) {
752 lsm
.cmd_type
= LTTNG_CREATE_SESSION_URI
;
754 copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
755 /* Anything bigger than zero, the consumer(s) will be enabled */
756 lsm
.u
.create_uri
.enable_consumer
= enable_consumer
;
757 memcpy(&lsm
.u
.create_uri
.ctrl_uri
, ctrl_uri
,
758 sizeof(lsm
.u
.create_uri
.ctrl_uri
));
761 * The only possible scenario where data_uri is NULL is for a local
762 * consumer where the output is at a specified path name on the
765 memcpy(&lsm
.u
.create_uri
.data_uri
, data_uri
,
766 sizeof(lsm
.u
.create_uri
.data_uri
));
769 return ask_sessiond(&lsm
, NULL
);
773 * Destroy session using name.
774 * Returns size of returned session payload data or a negative error code.
776 int lttng_destroy_session(const char *session_name
)
778 struct lttcomm_session_msg lsm
;
780 if (session_name
== NULL
) {
784 lsm
.cmd_type
= LTTNG_DESTROY_SESSION
;
786 copy_string(lsm
.session
.name
, session_name
, sizeof(lsm
.session
.name
));
788 return ask_sessiond(&lsm
, NULL
);
792 * Ask the session daemon for all available sessions.
793 * Sets the contents of the sessions array.
794 * Returns the number of lttng_session entries in sessions;
795 * on error, returns a negative value.
797 int lttng_list_sessions(struct lttng_session
**sessions
)
800 struct lttcomm_session_msg lsm
;
802 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
803 ret
= ask_sessiond(&lsm
, (void**) sessions
);
808 return ret
/ sizeof(struct lttng_session
);
812 * Ask the session daemon for all available domains of a session.
813 * Sets the contents of the domains array.
814 * Returns the number of lttng_domain entries in domains;
815 * on error, returns a negative value.
817 int lttng_list_domains(const char *session_name
,
818 struct lttng_domain
**domains
)
821 struct lttcomm_session_msg lsm
;
823 if (session_name
== NULL
) {
827 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
829 copy_string(lsm
.session
.name
, session_name
, sizeof(lsm
.session
.name
));
831 ret
= ask_sessiond(&lsm
, (void**) domains
);
836 return ret
/ sizeof(struct lttng_domain
);
840 * Ask the session daemon for all available channels of a session.
841 * Sets the contents of the channels array.
842 * Returns the number of lttng_channel entries in channels;
843 * on error, returns a negative value.
845 int lttng_list_channels(struct lttng_handle
*handle
,
846 struct lttng_channel
**channels
)
849 struct lttcomm_session_msg lsm
;
851 if (handle
== NULL
) {
855 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
856 copy_string(lsm
.session
.name
, handle
->session_name
,
857 sizeof(lsm
.session
.name
));
859 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
861 ret
= ask_sessiond(&lsm
, (void**) channels
);
866 return ret
/ sizeof(struct lttng_channel
);
870 * Ask the session daemon for all available events of a session channel.
871 * Sets the contents of the events array.
872 * Returns the number of lttng_event entries in events;
873 * on error, returns a negative value.
875 int lttng_list_events(struct lttng_handle
*handle
,
876 const char *channel_name
, struct lttng_event
**events
)
879 struct lttcomm_session_msg lsm
;
881 /* Safety check. An handle and channel name are mandatory */
882 if (handle
== NULL
|| channel_name
== NULL
) {
886 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
887 copy_string(lsm
.session
.name
, handle
->session_name
,
888 sizeof(lsm
.session
.name
));
889 copy_string(lsm
.u
.list
.channel_name
, channel_name
,
890 sizeof(lsm
.u
.list
.channel_name
));
892 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
894 ret
= ask_sessiond(&lsm
, (void**) events
);
899 return ret
/ sizeof(struct lttng_event
);
903 * Sets the tracing_group variable with name.
904 * This function allocates memory pointed to by tracing_group.
905 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
907 int lttng_set_tracing_group(const char *name
)
913 if (asprintf(&tracing_group
, "%s", name
) < 0) {
921 * Returns size of returned session payload data or a negative error code.
923 int lttng_calibrate(struct lttng_handle
*handle
,
924 struct lttng_calibrate
*calibrate
)
926 struct lttcomm_session_msg lsm
;
928 /* Safety check. NULL pointer are forbidden */
929 if (handle
== NULL
|| calibrate
== NULL
) {
933 lsm
.cmd_type
= LTTNG_CALIBRATE
;
934 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
936 memcpy(&lsm
.u
.calibrate
, calibrate
, sizeof(lsm
.u
.calibrate
));
938 return ask_sessiond(&lsm
, NULL
);
942 * Set default channel attributes.
943 * If either or both of the arguments are null, attr content is zeroe'd.
945 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
946 struct lttng_channel_attr
*attr
)
949 if (attr
== NULL
|| domain
== NULL
) {
953 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
955 switch (domain
->type
) {
956 case LTTNG_DOMAIN_KERNEL
:
957 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
958 attr
->switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
959 attr
->read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
961 attr
->subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
962 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
963 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
965 case LTTNG_DOMAIN_UST
:
967 case LTTNG_DOMAIN_UST_EXEC_NAME
:
968 case LTTNG_DOMAIN_UST_PID
:
969 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
971 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
972 attr
->switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
973 attr
->read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
975 attr
->subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
976 attr
->num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
977 attr
->output
= DEFAULT_UST_CHANNEL_OUTPUT
;
980 /* Default behavior: leave set to 0. */
986 * Check if session daemon is alive.
988 * Return 1 if alive or 0 if not.
989 * On error returns a negative value.
991 int lttng_session_daemon_alive(void)
995 ret
= set_session_daemon_path();
1001 if (strlen(sessiond_sock_path
) == 0) {
1002 /* No socket path set. Weird error */
1006 ret
= try_connect_sessiond(sessiond_sock_path
);
1017 * Set URI for a consumer for a session and domain.
1019 * Return 0 on success, else a negative value.
1021 int lttng_set_consumer_uri(struct lttng_handle
*handle
, struct lttng_uri
*uri
)
1023 struct lttcomm_session_msg lsm
;
1025 if (handle
== NULL
|| uri
== NULL
) {
1029 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
1031 copy_string(lsm
.session
.name
, handle
->session_name
,
1032 sizeof(lsm
.session
.name
));
1033 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1035 memcpy(&lsm
.u
.uri
, uri
, sizeof(lsm
.u
.uri
));
1037 return ask_sessiond(&lsm
, NULL
);
1041 * Enable consumer for a session and domain.
1043 * Return 0 on success, else a negative value.
1045 int lttng_enable_consumer(struct lttng_handle
*handle
)
1047 struct lttcomm_session_msg lsm
;
1049 if (handle
== NULL
) {
1053 lsm
.cmd_type
= LTTNG_ENABLE_CONSUMER
;
1055 copy_string(lsm
.session
.name
, handle
->session_name
,
1056 sizeof(lsm
.session
.name
));
1057 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1059 return ask_sessiond(&lsm
, NULL
);
1063 * Disable consumer for a session and domain.
1065 * Return 0 on success, else a negative value.
1067 int lttng_disable_consumer(struct lttng_handle
*handle
)
1069 struct lttcomm_session_msg lsm
;
1071 if (handle
== NULL
) {
1075 lsm
.cmd_type
= LTTNG_DISABLE_CONSUMER
;
1077 copy_string(lsm
.session
.name
, handle
->session_name
,
1078 sizeof(lsm
.session
.name
));
1079 copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1081 return ask_sessiond(&lsm
, NULL
);
1087 static void __attribute__((constructor
)) init()
1089 /* Set default session group */
1090 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);