From 163f4ee3e311b2f782b6ef46c930980f443acb69 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 26 May 2021 16:05:16 -0400 Subject: [PATCH 01/16] notification-thread: remove fd from pollset on LPOLLHUP and friends MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When an app dies, it's possible that the notification thread gets an epoll event (`LPOLLHUP`) that the socket was closed before it gets the _REMOVE_TRACER_SOURCE command for that source. In such cases, the notification thread should simply remove the file descriptor from the pollset and drain the notification on that file descriptor. It should _not_ remove the _source_element object from the list. The removal from the list should only be done when it receives the _REMOVE_TRACER_SOURCE command. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I9525315f9e92d0f6ae5e84e26b83a6b7207dce54 --- .../notification-thread-events.c | 128 ++++++++++-------- .../notification-thread-events.h | 6 +- src/bin/lttng-sessiond/notification-thread.c | 2 +- 3 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index c7037a482..c5ee4b11e 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -2110,95 +2110,115 @@ end: } static -int handle_notification_thread_command_remove_tracer_event_source( - struct notification_thread_state *state, - int tracer_event_source_fd, - enum lttng_error_code *_cmd_result) +struct notification_event_tracer_event_source_element * +find_tracer_event_source_element(struct notification_thread_state *state, + int tracer_event_source_fd) { - int ret = 0; - bool found = false; - enum lttng_error_code cmd_result = LTTNG_OK; - struct notification_event_tracer_event_source_element *source_element = NULL, *tmp; + struct notification_event_tracer_event_source_element *source_element; - cds_list_for_each_entry_safe(source_element, tmp, + cds_list_for_each_entry(source_element, &state->tracer_event_sources_list, node) { - if (source_element->fd != tracer_event_source_fd) { - continue; + if (source_element->fd == tracer_event_source_fd) { + goto end; } - - DBG("Removed tracer event source from poll set: tracer_event_source_fd = %d, domain = '%s'", - tracer_event_source_fd, - lttng_domain_type_str(source_element->domain)); - cds_list_del(&source_element->node); - found = true; - break; } - if (!found) { - /* - * This is temporarily allowed since the poll activity set is - * not properly cleaned-up for the moment. This is adressed in - * an upcoming fix. - */ - source_element = NULL; - goto end; - } + source_element = NULL; +end: + return NULL; +} - if (!source_element->is_fd_in_poll_set) { - /* Skip the poll set removal. */ - goto end; - } +static +int remove_tracer_event_source_from_pollset( + struct notification_thread_state *state, + struct notification_event_tracer_event_source_element *source_element) +{ + int ret = 0; + + assert(source_element->is_fd_in_poll_set); DBG3("Removing tracer event source from poll set: tracer_event_source_fd = %d, domain = '%s'", - tracer_event_source_fd, + source_element->fd, lttng_domain_type_str(source_element->domain)); /* Removing the fd from the event poll set. */ - ret = lttng_poll_del(&state->events, tracer_event_source_fd); + ret = lttng_poll_del(&state->events, source_element->fd); if (ret < 0) { ERR("Failed to remove tracer event source from poll set: tracer_event_source_fd = %d, domain = '%s'", - tracer_event_source_fd, + source_element->fd, lttng_domain_type_str(source_element->domain)); - cmd_result = LTTNG_ERR_FATAL; + ret = -1; goto end; } source_element->is_fd_in_poll_set = false; - ret = drain_event_notifier_notification_pipe(state, tracer_event_source_fd, + ret = drain_event_notifier_notification_pipe(state, source_element->fd, source_element->domain); if (ret) { ERR("Error draining event notifier notification: tracer_event_source_fd = %d, domain = %s", - tracer_event_source_fd, + source_element->fd, lttng_domain_type_str(source_element->domain)); - cmd_result = LTTNG_ERR_FATAL; + ret = -1; goto end; } - /* - * The drain_event_notifier_notification_pipe() call might have read - * data from an fd that we received in event in the latest _poll_wait() - * call. Make sure the thread call poll_wait() again to ensure we have - * a clean state. - */ - state->restart_poll = true; - end: - free(source_element); - *_cmd_result = cmd_result; return ret; } -int handle_notification_thread_remove_tracer_event_source_no_result( +int handle_notification_thread_tracer_event_source_died( struct notification_thread_state *state, int tracer_event_source_fd) { - int ret; - enum lttng_error_code cmd_result; + int ret = 0; + struct notification_event_tracer_event_source_element *source_element; + + source_element = find_tracer_event_source_element(state, + tracer_event_source_fd); + + assert(source_element); + + ret = remove_tracer_event_source_from_pollset(state, source_element); + if (ret) { + ERR("Failed to remove dead tracer event source from poll set"); + } - ret = handle_notification_thread_command_remove_tracer_event_source( - state, tracer_event_source_fd, &cmd_result); - (void) cmd_result; + return ret; +} + +static +int handle_notification_thread_command_remove_tracer_event_source( + struct notification_thread_state *state, + int tracer_event_source_fd, + enum lttng_error_code *_cmd_result) +{ + int ret = 0; + enum lttng_error_code cmd_result = LTTNG_OK; + struct notification_event_tracer_event_source_element *source_element = NULL; + + source_element = find_tracer_event_source_element(state, + tracer_event_source_fd); + + assert(source_element); + + /* Remove the tracer source from the list. */ + cds_list_del(&source_element->node); + + if (!source_element->is_fd_in_poll_set) { + /* Skip the poll set removal. */ + goto end; + } + + ret = remove_tracer_event_source_from_pollset(state, source_element); + if (ret) { + ERR("Failed to remove tracer event source from poll set"); + cmd_result = LTTNG_ERR_FATAL; + } + +end: + free(source_element); + *_cmd_result = cmd_result; return ret; } diff --git a/src/bin/lttng-sessiond/notification-thread-events.h b/src/bin/lttng-sessiond/notification-thread-events.h index dffd26773..265719181 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.h +++ b/src/bin/lttng-sessiond/notification-thread-events.h @@ -32,9 +32,9 @@ int handle_notification_thread_client_disconnect_all( int handle_notification_thread_trigger_unregister_all( struct notification_thread_state *state); -int handle_notification_thread_remove_tracer_event_source_no_result( - struct notification_thread_state *state, - int tracer_event_source_fd); +int handle_notification_thread_tracer_event_source_died( + struct notification_thread_state *state, + int tracer_event_source_fd); int handle_notification_thread_client_in( struct notification_thread_state *state, diff --git a/src/bin/lttng-sessiond/notification-thread.c b/src/bin/lttng-sessiond/notification-thread.c index d2f5a9441..0b39a5a3e 100644 --- a/src/bin/lttng-sessiond/notification-thread.c +++ b/src/bin/lttng-sessiond/notification-thread.c @@ -568,7 +568,7 @@ static int handle_event_notification_pipe(int event_source_fd, int ret = 0; if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) { - ret = handle_notification_thread_remove_tracer_event_source_no_result( + ret = handle_notification_thread_tracer_event_source_died( state, event_source_fd); if (ret) { ERR("Failed to remove event notification pipe from poll set: fd = %d", -- 2.34.1 From 810072601178ab06e866a74d11e6e06ccbc90f63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 8 Jul 2021 14:39:59 -0400 Subject: [PATCH 02/16] Clean-up: sessiond: return an lttng_error_code from list_triggers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau Change-Id: I5d44b508a2a5211894c0cc7b6d51a9a03dc8b3f2 --- src/bin/lttng-sessiond/cmd.c | 8 +++----- src/bin/lttng-sessiond/cmd.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 7715e1452..284f2921b 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4631,11 +4631,10 @@ end: return ret_code; } -int cmd_list_triggers(struct command_ctx *cmd_ctx, +enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, struct notification_thread_handle *notification_thread, struct lttng_triggers **return_triggers) { - int ret = 0; enum lttng_error_code ret_code; struct lttng_triggers *triggers = NULL; @@ -4643,16 +4642,15 @@ int cmd_list_triggers(struct command_ctx *cmd_ctx, ret_code = notification_thread_command_list_triggers( notification_thread, cmd_ctx->creds.uid, &triggers); if (ret_code != LTTNG_OK) { - ret = ret_code; goto end; } *return_triggers = triggers; triggers = NULL; - ret = LTTNG_OK; + ret_code = LTTNG_OK; end: lttng_triggers_destroy(triggers); - return ret; + return ret_code; } enum lttng_error_code cmd_execute_error_query(const struct lttng_credentials *cmd_creds, diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h index 33cac66ff..03f7cc1a4 100644 --- a/src/bin/lttng-sessiond/cmd.h +++ b/src/bin/lttng-sessiond/cmd.h @@ -152,7 +152,7 @@ enum lttng_error_code cmd_unregister_trigger( const struct lttng_trigger *trigger, struct notification_thread_handle *notification_thread_handle); -int cmd_list_triggers(struct command_ctx *cmd_ctx, +enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, struct notification_thread_handle *notification_thread_handle, struct lttng_triggers **return_triggers); enum lttng_error_code cmd_execute_error_query(const struct lttng_credentials *cmd_creds, -- 2.34.1 From bb17eb585257d944c7857d9400a4db247c49dcc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 8 Jul 2021 17:57:45 -0400 Subject: [PATCH 03/16] unix: receive pid on non-linux platforms MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a `pid` to the lttng_sock_cred structure definition used on non-Linux platforms and receive the peer's PID when receiving credentials. Signed-off-by: Jérémie Galarneau Change-Id: I9c92f6dda6441deca58f9cc85f846f5031cceb6e --- src/common/compat/socket.h | 10 +++++++++- src/common/unix.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/compat/socket.h b/src/common/compat/socket.h index a510473c3..464678292 100644 --- a/src/common/compat/socket.h +++ b/src/common/compat/socket.h @@ -117,6 +117,7 @@ typedef struct ucred lttng_sock_cred; struct lttng_sock_cred { uid_t uid; gid_t gid; + pid_t pid; }; typedef struct lttng_sock_cred lttng_sock_cred; @@ -155,7 +156,7 @@ typedef struct lttng_sock_cred lttng_sock_cred; #include static inline -int getpeereid(int s, uid_t *euid, gid_t *gid) +int getpeereid(int s, uid_t *euid, gid_t *gid, pid_t *pid) { int ret = 0; ucred_t *ucred = NULL; @@ -176,6 +177,13 @@ int getpeereid(int s, uid_t *euid, gid_t *gid) goto free; } *gid = ret; + + ret = ucred_getpid(ucred); + if (ret == -1) { + goto free; + } + *pid = ret; + ret = 0; free: ucred_free(ucred); diff --git a/src/common/unix.c b/src/common/unix.c index 023bff847..12622e5dd 100644 --- a/src/common/unix.c +++ b/src/common/unix.c @@ -1133,7 +1133,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, { int peer_ret; - peer_ret = getpeereid(sock, &creds->uid, &creds->gid); + peer_ret = getpeereid(sock, &creds->uid, &creds->gid, &creds->pid); if (peer_ret != 0) { return peer_ret; } -- 2.34.1 From 5682b2e6462875214549f5b5a1d9eb1d8df0950e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 9 Jul 2021 13:00:56 -0400 Subject: [PATCH 04/16] Fix: sessiond: list-triggers: don't return internal triggers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The session daemon uses triggers internally. For instance, the trigger and notification subsystem is used to implement the automatic rotation of sessions based on a size threshold. Currently, a user of the C API will see those internal triggers if it is running as the same user as the session daemon. This can be unexpected by user code that assumes it will be alone in creating triggers. Moreover, it is possible for external users to unregister those triggers which would cause bugs. As the triggers gain more capabilities, it is likely that the session daemon will keep using them to implement features internally. Thus, an internal "is_hidden" property is introduced in lttng_trigger. A "hidden" trigger is a trigger that is not returned by the listings. It is used to hide triggers that are used internally by the session daemon so that they can't be listed nor unregistered by external clients. This is a property that can only be set internally by the session daemon. As such, it is not serialized nor set by a "create_from_buffer" constructor. The hidden property is preserved by copies. Note that notifications originating from an "hidden" trigger will not be sent to clients that are not within the session daemon's process. Signed-off-by: Jérémie Galarneau Change-Id: I61b7949075172fcd428289e2eb670d03c19bdf71 --- include/lttng/trigger/trigger-internal.h | 29 +++++++++++ src/bin/lttng-sessiond/cmd.c | 7 +++ .../notification-thread-events.c | 14 ++++- .../notification-thread-internal.h | 1 + src/bin/lttng-sessiond/rotate.c | 2 + src/common/trigger.c | 52 +++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index d917ffa01..80cf0cb56 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -53,6 +53,23 @@ struct lttng_trigger { */ bool registered; + /* + * A "hidden" trigger is a trigger that is not externally listed. + * It is used to hide triggers that are used internally by the session + * daemon so that they can't be listed nor unregistered by external + * clients. + * + * This is a property that can only be set internally by the session + * daemon. As such, it is not serialized nor set by a + * "create_from_buffer" constructor. + * + * The hidden property is preserved by copies. + * + * Note that notifications originating from an "hidden" trigger will not + * be sent to clients that are not within the session daemon's process. + */ + bool is_hidden; + /* * The lock is used to protect against concurrent trigger execution and * trigger removal. @@ -118,6 +135,12 @@ LTTNG_HIDDEN bool lttng_trigger_is_equal( const struct lttng_trigger *a, const struct lttng_trigger *b); +LTTNG_HIDDEN +bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_set_hidden(struct lttng_trigger *trigger); + LTTNG_HIDDEN void lttng_trigger_get(struct lttng_trigger *trigger); @@ -165,6 +188,12 @@ LTTNG_HIDDEN int lttng_triggers_add( struct lttng_triggers *triggers, struct lttng_trigger *trigger); +/* + * Remove all triggers marked as hidden from the provided trigger set. + */ +LTTNG_HIDDEN +int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers); + /* * Serialize a trigger set to an lttng_payload object. * Return LTTNG_OK on success, negative lttng error code on error. diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 284f2921b..3349ff000 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4635,6 +4635,7 @@ enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, struct notification_thread_handle *notification_thread, struct lttng_triggers **return_triggers) { + int ret; enum lttng_error_code ret_code; struct lttng_triggers *triggers = NULL; @@ -4645,6 +4646,12 @@ enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, goto end; } + ret = lttng_triggers_remove_hidden_triggers(triggers); + if (ret) { + ret_code = LTTNG_ERR_UNK; + goto end; + } + *return_triggers = triggers; triggers = NULL; ret_code = LTTNG_OK; diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index c5ee4b11e..109378411 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -3814,9 +3814,11 @@ int client_handle_message_handshake(struct notification_client *client, &client->communication.inbound.creds); client->gid = LTTNG_SOCK_GET_GID_CRED( &client->communication.inbound.creds); - DBG("Received handshake from client (uid = %u, gid = %u) with version %i.%i", + client->is_sessiond = LTTNG_SOCK_GET_PID_CRED(&client->communication.inbound.creds) == getpid(); + DBG("Received handshake from client: uid = %u, gid = %u, protocol version = %i.%i, client is sessiond = %s", client->uid, client->gid, (int) client->major, - (int) client->minor); + (int) client->minor, + client->is_sessiond ? "true" : "false"); if (handshake_client->major != LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR) { @@ -4414,6 +4416,14 @@ int notification_client_list_send_evaluation( goto skip_client; } + if (lttng_trigger_is_hidden(trigger) && !client->is_sessiond) { + /* + * Notifications resulting from an hidden trigger are + * only sent to the session daemon. + */ + continue; + } + if (source_object_creds) { if (client->uid != lttng_credentials_get_uid(source_object_creds) && client->gid != lttng_credentials_get_gid(source_object_creds) && diff --git a/src/bin/lttng-sessiond/notification-thread-internal.h b/src/bin/lttng-sessiond/notification-thread-internal.h index e835bd6af..800e8fd83 100644 --- a/src/bin/lttng-sessiond/notification-thread-internal.h +++ b/src/bin/lttng-sessiond/notification-thread-internal.h @@ -142,6 +142,7 @@ struct notification_client { uint8_t major, minor; uid_t uid; gid_t gid; + bool is_sessiond; /* * Indicates if the credentials and versions of the client have been * checked. diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.c index ec0aa6668..cdf95f353 100644 --- a/src/bin/lttng-sessiond/rotate.c +++ b/src/bin/lttng-sessiond/rotate.c @@ -92,6 +92,8 @@ int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64 goto end; } + /* Ensure this trigger is not visible to external users. */ + lttng_trigger_set_hidden(session->rotate_trigger); lttng_trigger_set_credentials( session->rotate_trigger, &session_creds); diff --git a/src/common/trigger.c b/src/common/trigger.c index a599fa398..e708694b1 100644 --- a/src/common/trigger.c +++ b/src/common/trigger.c @@ -370,9 +370,26 @@ bool lttng_trigger_is_equal( return false; } + if (a->is_hidden != b->is_hidden) { + return false; + } + return true; } +LTTNG_HIDDEN +bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger) +{ + return trigger->is_hidden; +} + +LTTNG_HIDDEN +void lttng_trigger_set_hidden(struct lttng_trigger *trigger) +{ + assert(!trigger->is_hidden); + trigger->is_hidden = true; +} + LTTNG_HIDDEN enum lttng_trigger_status lttng_trigger_set_name(struct lttng_trigger *trigger, const char* name) @@ -550,6 +567,40 @@ int lttng_triggers_add( return ret; } +LTTNG_HIDDEN +int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers) +{ + int ret; + unsigned int trigger_count, i = 0; + enum lttng_trigger_status trigger_status; + + assert(triggers); + + trigger_status = lttng_triggers_get_count(triggers, &trigger_count); + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); + + while (i < trigger_count) { + const struct lttng_trigger *trigger = + lttng_triggers_get_at_index(triggers, i); + + if (lttng_trigger_is_hidden(trigger)) { + ret = lttng_dynamic_pointer_array_remove_pointer( + &triggers->array, i); + if (ret) { + goto end; + } + + trigger_count--; + } else { + i++; + } + } + + ret = 0; +end: + return ret; +} + const struct lttng_trigger *lttng_triggers_get_at_index( const struct lttng_triggers *triggers, unsigned int index) { @@ -942,6 +993,7 @@ struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger) copy->tracer_token = trigger->tracer_token; copy->registered = trigger->registered; + copy->is_hidden = trigger->is_hidden; goto end; error_cleanup_trigger: -- 2.34.1 From ffa1e278efc85ea36309e847347d4433641e8b0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 9 Jul 2021 13:00:48 -0400 Subject: [PATCH 05/16] Tests: add hidden trigger visibility test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a regression test for the previous commit that verifies that internal triggers used by the session daemon to implement various features (automatic session rotations based on their consumed size, in this instance) are not visible to users of liblttng-ctl. The test is written in C to use the library directly. This is needed since the `lttng` client filters-out anonymous triggers and thus, would not allow us to see those triggers since they are anonymous by default. Signed-off-by: Jérémie Galarneau Change-Id: I1b8fca648953b8cba49a9888593b3486457d01b2 --- configure.ac | 1 + tests/regression/Makefile.am | 3 +- tests/regression/tools/trigger/Makefile.am | 2 +- .../tools/trigger/hidden/Makefile.am | 28 +++ .../tools/trigger/hidden/hidden_trigger.c | 181 ++++++++++++++++++ .../tools/trigger/hidden/test_hidden_trigger | 26 +++ 6 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 tests/regression/tools/trigger/hidden/Makefile.am create mode 100644 tests/regression/tools/trigger/hidden/hidden_trigger.c create mode 100755 tests/regression/tools/trigger/hidden/test_hidden_trigger diff --git a/configure.ac b/configure.ac index 932615150..ecc5ce429 100644 --- a/configure.ac +++ b/configure.ac @@ -1151,6 +1151,7 @@ AC_CONFIG_FILES([ tests/regression/tools/trigger/start-stop/Makefile tests/regression/tools/trigger/utils/Makefile tests/regression/tools/trigger/name/Makefile + tests/regression/tools/trigger/hidden/Makefile tests/regression/ust/Makefile tests/regression/ust/nprocesses/Makefile tests/regression/ust/high-throughput/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 58269d15d..dac6f84e6 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -54,7 +54,8 @@ TESTS = tools/base-path/test_ust \ tools/trigger/test_add_trigger_cli \ tools/trigger/test_list_triggers_cli \ tools/trigger/test_remove_trigger_cli \ - tools/trigger/name/test_trigger_name_backwards_compat + tools/trigger/name/test_trigger_name_backwards_compat \ + tools/trigger/hidden/test_hidden_trigger if HAVE_LIBLTTNG_UST_CTL SUBDIRS += ust diff --git a/tests/regression/tools/trigger/Makefile.am b/tests/regression/tools/trigger/Makefile.am index fe5dd9744..110f86cc9 100644 --- a/tests/regression/tools/trigger/Makefile.am +++ b/tests/regression/tools/trigger/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=utils start-stop rate-policy name +SUBDIRS=utils start-stop rate-policy name hidden noinst_SCRIPTS = test_add_trigger_cli \ test_list_triggers_cli \ diff --git a/tests/regression/tools/trigger/hidden/Makefile.am b/tests/regression/tools/trigger/hidden/Makefile.am new file mode 100644 index 000000000..ef383fde9 --- /dev/null +++ b/tests/regression/tools/trigger/hidden/Makefile.am @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0-only + +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils/ -I$(srcdir) + +LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la +LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la + +noinst_PROGRAMS = hidden_trigger +hidden_trigger_CFLAGS = $(AM_CFLAGS) +hidden_trigger_SOURCES = hidden_trigger.c +hidden_trigger_LDADD = $(LIBTAP) $(LIBLTTNG_CTL) + +noinst_SCRIPTS = test_hidden_trigger +EXTRA_DIST = test_hidden_trigger + +all-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + cp -f $(srcdir)/$$script $(builddir); \ + done; \ + fi + +clean-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + rm -f $(builddir)/$$script; \ + done; \ + fi diff --git a/tests/regression/tools/trigger/hidden/hidden_trigger.c b/tests/regression/tools/trigger/hidden/hidden_trigger.c new file mode 100644 index 000000000..3ff126562 --- /dev/null +++ b/tests/regression/tools/trigger/hidden/hidden_trigger.c @@ -0,0 +1,181 @@ +/* + * trigger_name.c + * + * Test that hidden triggers are not visible to liblttng-ctl. + * + * Copyright (C) 2021 Jérémie Galarneau + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#define TEST_COUNT 1 + +#define TEST_SESSION_NAME "test_session" +#define TEST_CHANNEL_NAME "test_channel" + +static +int get_registered_triggers_count(void) +{ + int ret; + enum lttng_error_code ret_code; + enum lttng_trigger_status trigger_status; + struct lttng_triggers *triggers = NULL; + unsigned int trigger_count; + + ret_code = lttng_list_triggers(&triggers); + if (ret_code != LTTNG_OK) { + fail("Failed to list triggers"); + ret = -1; + goto end; + } + + trigger_status = lttng_triggers_get_count(triggers, &trigger_count); + if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { + fail("Failed to get count of triggers returned by listing"); + ret = -1; + goto end; + } + + ret = (int) trigger_count; + +end: + lttng_triggers_destroy(triggers); + return ret; +} + +static +int setup_session_with_size_rotation_schedule(const char *session_output_path) +{ + int ret; + struct lttng_session_descriptor *session_desriptor = NULL; + enum lttng_error_code ret_code; + struct lttng_handle ust_channel_handle = { + .session_name = TEST_SESSION_NAME, + .domain.type = LTTNG_DOMAIN_UST, + .domain.buf_type = LTTNG_BUFFER_PER_UID, + }; + struct lttng_channel channel_cfg = { + .name = TEST_CHANNEL_NAME, + .enabled = 1, + .attr.overwrite = -1, + .attr.subbuf_size = sysconf(_SC_PAGESIZE) * 8, + .attr.num_subbuf = 8, + .attr.output = LTTNG_EVENT_MMAP, + }; + enum lttng_rotation_status rotation_status; + struct lttng_rotation_schedule *rotation_schedule = NULL; + + session_desriptor = lttng_session_descriptor_local_create( + TEST_SESSION_NAME, session_output_path); + if (!session_desriptor) { + fail("Failed to create session descriptor for session `%s`", + TEST_SESSION_NAME); + ret = -1; + goto end; + } + + ret_code = lttng_create_session_ext(session_desriptor); + if (ret_code != LTTNG_OK) { + fail("Failed to create session `%s`: %s", TEST_SESSION_NAME, + lttng_strerror(-ret_code)); + ret = -1; + goto end; + } + + ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg); + if (ret) { + fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME, + lttng_strerror(ret)); + ret = -1; + goto end; + } + + ret = lttng_start_tracing(TEST_SESSION_NAME); + if (ret) { + fail("Failed to start session `%s`: %s", TEST_SESSION_NAME, + lttng_strerror(ret)); + ret = -1; + goto end; + } + + rotation_schedule = lttng_rotation_schedule_size_threshold_create(); + if (!rotation_schedule) { + fail("Failed to create rotation schedule descriptor"); + ret = -1; + goto end; + } + + /* + * The rotation schedule size threshold doesn't matter; no event rules + * were specified so the session consumed size should not grow over + * time. + */ + rotation_status = lttng_rotation_schedule_size_threshold_set_threshold( + rotation_schedule, sysconf(_SC_PAGESIZE) * 4096); + if (rotation_status != LTTNG_ROTATION_STATUS_OK) { + fail("Failed to set size threshold of session rotation schedule"); + ret = -1; + goto end; + } + + rotation_status = lttng_session_add_rotation_schedule( + TEST_SESSION_NAME, rotation_schedule); + if (rotation_status != LTTNG_ROTATION_STATUS_OK) { + fail("Failed to set size-based rotation schedule on session `%s`", + TEST_SESSION_NAME); + ret = -1; + goto end; + } + + ret = 0; +end: + lttng_session_descriptor_destroy(session_desriptor); + lttng_rotation_schedule_destroy(rotation_schedule); + return ret; +} + +int main(int argc, const char **argv) +{ + int ret; + + if (argc != 2) { + fail("Missing trace path"); + goto end; + } + + plan_tests(TEST_COUNT); + + if (get_registered_triggers_count() != 0) { + fail("Session daemon already has registered triggers, bailing out"); + goto end; + } + + ret = setup_session_with_size_rotation_schedule(argv[1]); + if (ret) { + goto end; + } + + ok(get_registered_triggers_count() == 0, + "No triggers visible while session has an enabled size-based rotation schedule"); + + ret = lttng_destroy_session(TEST_SESSION_NAME); + if (ret) { + fail("Failed to destroy session `%s`", TEST_SESSION_NAME); + goto end; + } +end: + return exit_status(); +} diff --git a/tests/regression/tools/trigger/hidden/test_hidden_trigger b/tests/regression/tools/trigger/hidden/test_hidden_trigger new file mode 100755 index 000000000..0adce61eb --- /dev/null +++ b/tests/regression/tools/trigger/hidden/test_hidden_trigger @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Copyright (C) 2021 Jérémie Galarneau +# +# SPDX-License-Identifier: LGPL-2.1-only + +TEST_DESC="Triggers - Hidden internal triggers" + +CURDIR=$(dirname "$0")/ +TESTDIR=${CURDIR}/../../../.. +TRACE_PATH=$(mktemp --tmpdir -d -t tmp.test_trigger_hidden.XXXXXX) + +# shellcheck source=../../../../utils/utils.sh +source "$TESTDIR/utils/utils.sh" + +HIDDEN_TRIGGER_BIN="$CURDIR/hidden_trigger" + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond_notap + +$HIDDEN_TRIGGER_BIN "$TRACE_PATH" + +stop_lttng_sessiond_notap + +rm -rf "$TRACE_PATH" -- 2.34.1 From ec4723516f5a1375c4639447225965f8735aadd3 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Thu, 21 Jan 2021 12:00:03 -0500 Subject: [PATCH 06/16] Cleanup: fix comments in `duplicate_{stream,channel}_object()` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I5089d09880d21842bf264f6c30ec7fd5e72b93df --- src/bin/lttng-sessiond/ust-app.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 4f136550c..c902b2176 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -3013,7 +3013,7 @@ static int duplicate_stream_object(struct buffer_reg_stream *reg_stream, assert(reg_stream); assert(stream); - /* Reserve the amount of file descriptor we need. */ + /* Duplicating a stream requires 2 new fds. Reserve them. */ ret = lttng_fd_get(LTTNG_FD_APPS, 2); if (ret < 0) { ERR("Exhausted number of available FD upon duplicate stream"); @@ -3049,7 +3049,7 @@ static int duplicate_channel_object(struct buffer_reg_channel *buf_reg_chan, assert(buf_reg_chan); assert(ua_chan); - /* Need two fds for the channel. */ + /* Duplicating a channel requires 1 new fd. Reserve it. */ ret = lttng_fd_get(LTTNG_FD_APPS, 1); if (ret < 0) { ERR("Exhausted number of available FD upon duplicate channel"); -- 2.34.1 From bcdc812dd6ee5dce6ee67f0758969b08f3184974 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Thu, 8 Jul 2021 12:35:58 -0400 Subject: [PATCH 07/16] Tests: MI: add `diag` statements to test functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Ie56e23a3d0796d1edb07e2fd7cdc259816ac0133 --- tests/regression/tools/mi/test_mi | 40 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/regression/tools/mi/test_mi b/tests/regression/tools/mi/test_mi index 72b96aac1..e17cad130 100755 --- a/tests/regression/tools/mi/test_mi +++ b/tests/regression/tools/mi/test_mi @@ -92,7 +92,6 @@ function is_command_success () local xpath=$XPATH_COMMAND_SUCCESS - echo $xml #Extract the success element #expect false extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result @@ -132,6 +131,8 @@ function test_version () function test_create_session () { + diag "Test create session" + local session_name="testSession" OUTPUT_FILE="create_session.xml" @@ -152,6 +153,8 @@ function test_create_session () function test_destroy_session () { + diag "Test destroy session" + local session_name=( "testSession1" "testSession2" @@ -198,6 +201,8 @@ function test_destroy_session () function test_list_sessions () { + diag "Test list sessions" + local session_name=( "testSession1" "testSession2" @@ -229,6 +234,8 @@ function test_list_sessions () function test_list_session_long_path () { + diag "Test list session long path" + local session_name="session_long_path" output_basedir=$OUTPUT_DIR/$(randstring 254 0) @@ -251,10 +258,10 @@ function test_list_session_long_path () } function test_ust_channel () { + diag "Test UST channel" + local session_name="testsession" - local channel_name=("channelUst0" - "channelUst1" - "channelUst2") + local channel_name=("channelUst0" "channelUst1" "channelUst2") OUTPUT_FILE="ust_channel.xml" @@ -310,6 +317,8 @@ function test_ust_channel () function test_ust_lttng_event () { + diag "Test UST event" + local session_name="testSession" local channel_name="testChannel" local event=("ev1" "ev2" "ev3") @@ -382,6 +391,8 @@ function test_ust_lttng_event () function test_list_channel () { + diag "Test list channel" + local session_name="testSession" local channel_name="testChannel" local event=("ev1" "ev2" "ev3") @@ -429,6 +440,8 @@ function test_list_channel () function test_list_domain () { + diag "Test list domain" + local session_name="testSession" local channel_name="testChannel" local event=("ev1" "ev2" "ev3") @@ -477,6 +490,8 @@ function test_list_domain () function test_list_session () { + diag "Test list session" + local session_name="testSession" local channel_name="testChannel" local event=("ev1" "ev2" "ev3") @@ -485,6 +500,7 @@ function test_list_session () #Test buid up OUTPUT_DEST=$DEVNULL + create_lttng_session_ok $session_name $OUTPUT_DIR enable_ust_lttng_channel_ok $session_name $channel_name @@ -518,6 +534,8 @@ function test_list_session () function test_list_ust_event () { + diag "Test list ust event" + local file_sync_after_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") local file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") @@ -566,7 +584,10 @@ function test_list_ust_event () rm -f ${file_sync_before_last} } -function test_start_stop () { +function test_start_stop () +{ + diag "Test start-stop" + local session_name="testStartStopSession" local channel_name="startStopChannel" @@ -574,6 +595,7 @@ function test_start_stop () { #Test buid up OUTPUT_DEST=$DEVNULL + create_lttng_session_ok $session_name $OUTPUT_DIR #Test fail command @@ -648,12 +670,14 @@ function test_start_stop () { destroy_lttng_sessions } -function test_snapshot () { +function test_snapshot () +{ + diag "Test snapshot" + local session_name="testSnapshotAdd" local snapshot_path="$OUTPUT_DIR/snapshotoutput" OUTPUT_FILE="snapshot.xml" - #Test buid up OUTPUT_DEST=$DEVNULL create_lttng_session_no_output $session_name @@ -874,6 +898,8 @@ function test_add_context_list() function test_clear_session () { + diag "Test clear session" + # Since the session are not started there is no real clear done. # We are testing the MI output only here. local session_name=( -- 2.34.1 From 8ec89801730aef6c4af48c45938380e7dec71d59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 12 Jul 2021 18:42:57 -0400 Subject: [PATCH 08/16] Fix: sessiond: notification: find_tracer_event_source returns NULL MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Due to a bad edit of the original patch (my bad!) find_tracer_event_source_element always returns NULL. Signed-off-by: Jérémie Galarneau Change-Id: I7febee1d803034a06d5063a2cc9179c4edef4809 --- src/bin/lttng-sessiond/notification-thread-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index 109378411..9e5ec5091 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -2125,7 +2125,7 @@ find_tracer_event_source_element(struct notification_thread_state *state, source_element = NULL; end: - return NULL; + return source_element; } static -- 2.34.1 From 4dc766fa8a92a9862c3f9d560751a941b4599380 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 14 Jul 2021 15:19:15 -0400 Subject: [PATCH 09/16] Build fix: retrieve unix socket peer PID on non-unix platforms MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The previous attempt at extending the credential retrieval wrapper was broken and didn't build on FreeBSD, macOS, and cygwin. A platform-specific way of retrieving the PID of a unix peer is implemented for FreeBSD (getsockopt using LOCAL_PEERCRED, note that the cr_pid field is only available from FreeBSD 13 and up), macOS (getsockopt using LOCAL_PEERPID, macOS 10.8+), and Solaris (getpeerucreds). Signed-off-by: Jérémie Galarneau Change-Id: Ifcf522c70ee4c2e0799293ae0961f41aebff5056 --- src/common/compat/socket.h | 156 +++++++++++++++++++++++++++---------- src/common/unix.c | 37 ++++----- 2 files changed, 132 insertions(+), 61 deletions(-) diff --git a/src/common/compat/socket.h b/src/common/compat/socket.h index 464678292..fda00e536 100644 --- a/src/common/compat/socket.h +++ b/src/common/compat/socket.h @@ -10,6 +10,7 @@ #include #include +#include #include @@ -97,8 +98,58 @@ ssize_t lttng_recvmsg_nosigpipe(int sockfd, struct msghdr *msg) } #endif +#ifdef __sun__ + +# ifndef CMSG_ALIGN +# ifdef _CMSG_DATA_ALIGN +# define CMSG_ALIGN(len) _CMSG_DATA_ALIGN(len) +# else + /* aligning to sizeof (long) is assumed to be portable (fd.o#40235) */ +# define CMSG_ALIGN(len) (((len) + sizeof (long) - 1) & ~(sizeof (long) - 1)) +# endif +# ifndef CMSG_SPACE +# define CMSG_SPACE(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + CMSG_ALIGN (len)) +# endif +# ifndef CMSG_LEN +# define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) +# endif +# endif + +#include -#ifdef __linux__ +static inline +int getpeereid(int s, uid_t *euid, gid_t *gid) +{ + int ret = 0; + ucred_t *ucred = NULL; + + ret = getpeerucred(s, &ucred); + if (ret == -1) { + goto end; + } + + ret = ucred_geteuid(ucred); + if (ret == -1) { + goto free; + } + *euid = ret; + + ret = ucred_getrgid(ucred); + if (ret == -1) { + goto free; + } + *gid = ret; + + ret = 0; +free: + ucred_free(ucred); +end: + return ret; +} +#endif /* __sun__ */ + + +#if defined(__linux__) || defined(__CYGWIN__) #define LTTNG_SOCK_CREDS SCM_CREDENTIALS @@ -112,7 +163,7 @@ typedef struct ucred lttng_sock_cred; #define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid #define LTTNG_SOCK_GET_PID_CRED(c) LTTNG_REF(c)->pid -#elif (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__) || defined(__APPLE__)) +#elif (defined(__FreeBSD__) || defined(__sun__) || defined(__APPLE__)) struct lttng_sock_cred { uid_t uid; @@ -124,39 +175,27 @@ typedef struct lttng_sock_cred lttng_sock_cred; #define LTTNG_SOCK_SET_UID_CRED(c, u) LTTNG_REF(c)->uid = u #define LTTNG_SOCK_SET_GID_CRED(c, g) LTTNG_REF(c)->gid = g -#define LTTNG_SOCK_SET_PID_CRED(c, p) +#define LTTNG_SOCK_SET_PID_CRED(c, p) LTTNG_REF(c)->pid = p #define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid #define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid -#define LTTNG_SOCK_GET_PID_CRED(c) -1 - -#else -#error "Please add support for your OS." -#endif /* __linux__ , __FreeBSD__ */ - - -#ifdef __sun__ +#define LTTNG_SOCK_GET_PID_CRED(c) LTTNG_REF(c)->pid -# ifndef CMSG_ALIGN -# ifdef _CMSG_DATA_ALIGN -# define CMSG_ALIGN(len) _CMSG_DATA_ALIGN(len) -# else - /* aligning to sizeof (long) is assumed to be portable (fd.o#40235) */ -# define CMSG_ALIGN(len) (((len) + sizeof (long) - 1) & ~(sizeof (long) - 1)) -# endif -# ifndef CMSG_SPACE -# define CMSG_SPACE(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + CMSG_ALIGN (len)) -# endif -# ifndef CMSG_LEN -# define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) -# endif -# endif +#ifdef __APPLE__ +static inline +int lttng_get_unix_socket_peer_pid(int socket_fd, pid_t *pid) +{ + /* The getsockopt LOCAL_PEERPID option is available since macOS 10.8. */ + return getsockopt(socket_fd, SOL_LOCAL, LOCAL_PEERPID, pid, + &((socklen_t) {sizeof(*pid)})); +} -#include +#elif defined(__sun__) +/* Use the getpeerucreds interface on Solaris. */ static inline -int getpeereid(int s, uid_t *euid, gid_t *gid, pid_t *pid) +int lttng_get_unix_socket_peer_pid(int socket_fd, pid_t *pid) { int ret = 0; ucred_t *ucred = NULL; @@ -166,24 +205,12 @@ int getpeereid(int s, uid_t *euid, gid_t *gid, pid_t *pid) goto end; } - ret = ucred_geteuid(ucred); - if (ret == -1) { - goto free; - } - *euid = ret; - - ret = ucred_getrgid(ucred); - if (ret == -1) { - goto free; - } - *gid = ret; - ret = ucred_getpid(ucred); if (ret == -1) { goto free; } - *pid = ret; + *pid = ret; ret = 0; free: ucred_free(ucred); @@ -191,6 +218,53 @@ end: return ret; } -#endif /* __sun__ */ +#elif defined(__FreeBSD__) + +#include + +static inline +int lttng_get_unix_socket_peer_pid(int socket_fd, pid_t *pid) +{ + int ret; + struct xucred sock_creds = {}; + + /* Only available in FreeBSD 13.0 and up. */ + ret = getsockopt(socket_fd, SOL_LOCAL, LOCAL_PEERCRED, &sock_creds, + &((socklen_t) {sizeof(sock_creds)})); + if (ret) { + goto end; + } + + *pid = sock_creds.cr_pid; +end: + return ret; +} + +#endif /* __APPLE__ */ + + +static inline +int lttng_get_unix_socket_peer_creds(int socket_fd, struct lttng_sock_cred *creds) +{ + int ret; + + /* This is a BSD extension that is supported by Cygwin. */ + ret = getpeereid(socket_fd, &creds->uid, &creds->gid); + if (ret) { + goto end; + } + + /* + * Getting a peer's PID is a bit more troublesome as it is platform + * specific. + */ + ret = lttng_get_unix_socket_peer_pid(socket_fd, &creds->pid); +end: + return ret; +} + +#else +#error "Please add support for your OS." +#endif /* __linux__ , __FreeBSD__, __APPLE__ */ #endif /* _COMPAT_SOCKET_H */ diff --git a/src/common/unix.c b/src/common/unix.c index 12622e5dd..4c5c7acc6 100644 --- a/src/common/unix.c +++ b/src/common/unix.c @@ -992,14 +992,14 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, const void *buf, size_t len) struct msghdr msg; struct iovec iov[1]; ssize_t ret = -1; -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) struct cmsghdr *cmptr; size_t sizeof_cred = sizeof(lttng_sock_cred); char anc_buf[CMSG_SPACE(sizeof_cred)]; lttng_sock_cred *creds; memset(anc_buf, 0, CMSG_SPACE(sizeof_cred) * sizeof(char)); -#endif /* __linux__ */ +#endif /* __linux__, __CYGWIN__ */ memset(&msg, 0, sizeof(msg)); @@ -1012,7 +1012,7 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, const void *buf, size_t len) msg.msg_iov = iov; msg.msg_iovlen = 1; -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) msg.msg_control = (caddr_t) anc_buf; msg.msg_controllen = CMSG_LEN(sizeof_cred); @@ -1029,7 +1029,7 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, const void *buf, size_t len) LTTNG_SOCK_SET_UID_CRED(creds, geteuid()); LTTNG_SOCK_SET_GID_CRED(creds, getegid()); LTTNG_SOCK_SET_PID_CRED(creds, getpid()); -#endif /* __linux__ */ +#endif /* __linux__, __CYGWIN__ */ do { ret = sendmsg(sock, &msg, 0); @@ -1059,11 +1059,11 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, struct iovec iov[1]; ssize_t ret; size_t len_last; -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) struct cmsghdr *cmptr; size_t sizeof_cred = sizeof(lttng_sock_cred); char anc_buf[CMSG_SPACE(sizeof_cred)]; -#endif /* __linux__ */ +#endif /* __linux__, __CYGWIN__ */ assert(sock); assert(buf); @@ -1078,10 +1078,10 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, msg.msg_iov = iov; msg.msg_iovlen = 1; -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) msg.msg_control = anc_buf; msg.msg_controllen = sizeof(anc_buf); -#endif /* __linux__ */ +#endif /* __linux__, __CYGWIN__ */ do { len_last = iov[0].iov_len; @@ -1100,7 +1100,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, } /* Else ret = 0 meaning an orderly shutdown. */ -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) if (msg.msg_flags & MSG_CTRUNC) { fprintf(stderr, "Error: Control message truncated.\n"); ret = -1; @@ -1129,18 +1129,15 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, } memcpy(creds, CMSG_DATA(cmptr), sizeof_cred); -#elif (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__) || defined(__APPLE__)) - { - int peer_ret; - - peer_ret = getpeereid(sock, &creds->uid, &creds->gid, &creds->pid); - if (peer_ret != 0) { - return peer_ret; - } +#elif (defined(__FreeBSD__) || defined(__sun__) || defined(__APPLE__)) + if (lttng_get_unix_socket_peer_creds(sock, creds)) { + fprintf(stderr, "ARG\n"); + ret = -1; + goto end; } #else #error "Please implement credential support for your OS." -#endif /* __linux__ */ +#endif /* __linux__, __CYGWIN__ */ end: return ret; @@ -1149,7 +1146,7 @@ end: /* * Set socket option to use credentials passing. */ -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) LTTNG_HIDDEN int lttcomm_setsockopt_creds_unix_sock(int sock) { @@ -1162,7 +1159,7 @@ int lttcomm_setsockopt_creds_unix_sock(int sock) } return ret; } -#elif (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__) || defined(__APPLE__)) +#elif (defined(__FreeBSD__) || defined(__sun__) || defined(__APPLE__)) LTTNG_HIDDEN int lttcomm_setsockopt_creds_unix_sock(int sock) { -- 2.34.1 From 707602aa577ce7ed59b860971dfc51450cfeee80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 14 Jul 2021 20:44:44 -0400 Subject: [PATCH 10/16] Test: unix socket: test credential passing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since the credential passing over UNIX sockets now makes use of the pid, the compatiblity wrappers have become more complex as each platform appears to define its own way of accessing this information. This new test: - creates a named unix socket, - forks, - gets the parents and child to connect, - sends the child's credentials as a data payload and as credentials verified by the kernel - the parent checks that the two sets of credentials are equal. This is more of a sanity check for the compatibility wrappers used on non-Linux platforms. Signed-off-by: Jérémie Galarneau Change-Id: Ic0a6213afca7cc95a00617b052e7a145fc88625c --- tests/unit/test_unix_socket.c | 173 +++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_unix_socket.c b/tests/unit/test_unix_socket.c index b32a5174a..0a96fb589 100644 --- a/tests/unit/test_unix_socket.c +++ b/tests/unit/test_unix_socket.c @@ -19,13 +19,15 @@ #include #include #include +#include +#include #define HIGH_FD_COUNT LTTCOMM_MAX_SEND_FDS #define MESSAGE_COUNT 4 #define LARGE_PAYLOAD_SIZE 4 * 1024 #define LARGE_PAYLOAD_RECV_SIZE 100 -static const int TEST_COUNT = 33; +static const int TEST_COUNT = 37; /* For error.h */ int lttng_opt_quiet; @@ -499,6 +501,174 @@ error: lttng_payload_reset(&received_payload); } +static +void test_creds_passing(void) +{ + pid_t fork_ret = -1; + int ret, parent_socket = -1, child_connection_socket = -1; + ssize_t sock_ret; + char socket_dir_path[] = "/tmp/test.unix.socket.creds.passing.XXXXXX"; + char socket_path[PATH_MAX] = {}; + struct expected_creds { + uid_t euid; + gid_t egid; + pid_t pid; + } expected_creds; + + diag("Receive peer's effective uid, effective gid, and pid from a unix socket"); + + if (!mkdtemp(socket_dir_path)) { + PERROR("Failed to generate temporary socket location"); + goto error; + } + + strncat(socket_path, socket_dir_path, + sizeof(socket_path) - strlen(socket_path) - 1); + strncat(socket_path, "/test_unix_socket", + sizeof(socket_path) - strlen(socket_path) - 1); + + parent_socket = lttcomm_create_unix_sock(socket_path); + ok(parent_socket >= 0, "Created unix socket at path `%s`", socket_path); + if (parent_socket < 0) { + PERROR("Failed to create unix socket at path `%s`", socket_path); + goto error; + } + + ret = lttcomm_listen_unix_sock(parent_socket); + if (ret < 0) { + PERROR("Failed to mark parent socket as a passive socket"); + goto error; + } + + ret = lttcomm_setsockopt_creds_unix_sock(parent_socket); + if (ret) { + PERROR("Failed to set SO_PASSCRED on parent socket"); + goto error; + } + + fork_ret = fork(); + if (fork_ret < 0) { + PERROR("Failed to fork"); + goto error; + } + + if (fork_ret == 0) { + /* Child. */ + int child_socket; + + expected_creds = (struct expected_creds){ + .euid = geteuid(), + .egid = getegid(), + .pid = getpid(), + }; + + child_socket = lttcomm_connect_unix_sock(socket_path); + if (child_socket < 0) { + PERROR("Failed to connect to parent socket"); + goto error; + } + + ret = lttcomm_setsockopt_creds_unix_sock(child_socket); + if (ret) { + PERROR("Failed to set SO_PASSCRED on child socket"); + } + + sock_ret = lttcomm_send_creds_unix_sock(child_socket, &expected_creds, + sizeof(expected_creds)); + if (sock_ret < 0) { + PERROR("Failed to send expected credentials"); + } + + ret = close(child_socket); + if (ret) { + PERROR("Failed to close child socket"); + } + } else { + /* Parent. */ + int child_status; + pid_t wait_pid_ret; + lttng_sock_cred received_creds = {}; + + child_connection_socket = + lttcomm_accept_unix_sock(parent_socket); + if (child_connection_socket < 0) { + PERROR(); + goto error; + } + + ret = lttcomm_setsockopt_creds_unix_sock( + child_connection_socket); + if (ret) { + PERROR("Failed to set SO_PASSCRED on child connection socket"); + goto error; + } + + sock_ret = lttcomm_recv_creds_unix_sock(child_connection_socket, + &expected_creds, sizeof(expected_creds), + &received_creds); + if (sock_ret < 0) { + PERROR("Failed to receive credentials"); + goto error; + } + + wait_pid_ret = waitpid(fork_ret, &child_status, 0); + if (wait_pid_ret == -1) { + PERROR("Failed to wait for termination of child process"); + goto error; + } + if (!WIFEXITED(child_status) || WEXITSTATUS(child_status)) { + diag("Child process reported an error, test failed"); + goto error; + } + + ok(expected_creds.euid == received_creds.uid, + "Received the expected effective uid (%d == %d)", + expected_creds.euid, received_creds.uid); + ok(expected_creds.egid == received_creds.gid, + "Received the expected effective gid (%d == %d)", + expected_creds.egid, received_creds.gid); + ok(expected_creds.pid == received_creds.pid, + "Received the expected pid (%d == %d)", + expected_creds.pid, received_creds.pid); + } + +error: + if (parent_socket >= 0) { + ret = close(parent_socket); + if (ret) { + PERROR("Failed to close parent socket"); + } + } + + if (fork_ret == 0) { + if (child_connection_socket >= 0) { + ret = close(child_connection_socket); + if (ret) { + PERROR("Failed to close child connection socket"); + } + } + + /* Prevent libtap from printing a result for the child. */ + fclose(stdout); + fclose(stderr); + + /* Child exits at the end of this test. */ + exit(0); + } else if (parent_socket >= 0) { + ret = unlink(socket_path); + if (ret) { + PERROR("Failed to unlink socket at path `%s`", + socket_path); + } + + ret = rmdir(socket_dir_path); + if (ret) { + PERROR("Failed to remove test directory at `%s`", + socket_dir_path); + } + } +} + int main(void) { plan_tests(TEST_COUNT); @@ -506,6 +676,7 @@ int main(void) test_high_fd_count(HIGH_FD_COUNT); test_one_fd_per_message(MESSAGE_COUNT); test_receive_in_chunks(LARGE_PAYLOAD_SIZE, LARGE_PAYLOAD_RECV_SIZE); + test_creds_passing(); return exit_status(); } -- 2.34.1 From 54e92d5f4c74203b3aa555b7534fbb540664e0c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 16 Jul 2021 13:29:07 -0400 Subject: [PATCH 11/16] .gitignore: Add hidden trigger test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau Change-Id: Iab0fe77c0d4607d5469a7aa57d6bd784d47d8609 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d8c51e53e..ab6609952 100644 --- a/.gitignore +++ b/.gitignore @@ -110,6 +110,7 @@ compile_commands.json /tests/regression/tools/trigger/utils/notification-client /tests/regression/tools/trigger/name/trigger_name /tests/regression/tools/trigger/utils/register-some-triggers +/tests/regression/tools/trigger/hidden/hidden_trigger /tests/regression/ust/overlap/demo/demo /tests/regression/ust/linking/demo_builtin /tests/regression/ust/linking/demo_static -- 2.34.1 From 1ceda6f154db93be802eeea64bc9eb49840fd402 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 25 May 2021 15:57:59 -0400 Subject: [PATCH 12/16] Cleanup: rename `get_domain_str()` -> `lttng_domain_type_str()` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Both functions currently exist in the code base and accomplish the same goal. Let's keep only one of them. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I2254b846f0b5bdc883c86d970fde7daffa9e6155 --- src/bin/lttng/commands/add_context.c | 7 +++-- src/bin/lttng/commands/add_trigger.c | 1 + src/bin/lttng/commands/disable_channels.c | 4 ++- src/bin/lttng/commands/disable_events.c | 5 ++-- src/bin/lttng/commands/enable_channels.c | 5 +++- src/bin/lttng/commands/enable_events.c | 17 ++++++------ src/bin/lttng/commands/list.c | 3 ++- src/bin/lttng/utils.c | 33 ----------------------- src/bin/lttng/utils.h | 1 - src/common/mi-lttng.c | 1 - 10 files changed, 27 insertions(+), 50 deletions(-) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index b33eb1d14..de066e6dc 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -19,6 +19,7 @@ #include +#include #include #include "../command.h" @@ -810,11 +811,13 @@ static int add_context(char *session_name) } else { if (opt_channel_name) { MSG("%s context %s added to channel %s", - get_domain_str(dom.type), type->opt->symbol, + lttng_domain_type_str(dom.type), + type->opt->symbol, opt_channel_name); } else { MSG("%s context %s added to all channels", - get_domain_str(dom.type), type->opt->symbol); + lttng_domain_type_str(dom.type), + type->opt->symbol); } success = 1; } diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index 00f8f47e3..8fb79d378 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -18,6 +18,7 @@ #include "common/mi-lttng.h" #include "common/string-utils/string-utils.h" #include "common/utils.h" +#include /* For lttng_event_rule_type_str(). */ #include #include diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 344be237d..f75c5feb0 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -16,6 +16,7 @@ #include #include +#include #include "../command.h" @@ -155,7 +156,8 @@ static int disable_channels(char *session_name) } else { MSG("%s channel %s disabled for session %s", - get_domain_str(dom.type), channel_name, session_name); + lttng_domain_type_str(dom.type), + channel_name, session_name); enabled = 0; success = 1; } diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index a42c3a3cd..0bfd0c506 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -16,6 +16,7 @@ #include #include +#include #include "../command.h" @@ -226,7 +227,7 @@ static int disable_events(char *session_name) enabled = 0; success = 1; MSG("All %s events of type %s are disabled in channel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), print_event_type(opt_event_type), print_channel_name(channel_name)); } @@ -265,7 +266,7 @@ static int disable_events(char *session_name) enabled = 1; } else { MSG("%s %s of type %s disabled in channel %s for session %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), event_name, print_event_type(opt_event_type), print_channel_name(channel_name), diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index fa65b1eaa..dd79926f8 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -21,6 +21,8 @@ #include #include +#include + #include "../command.h" #include "../utils.h" @@ -304,7 +306,8 @@ static int enable_channel(char *session_name) } } else { MSG("%s channel %s enabled for session %s", - get_domain_str(dom.type), channel_name, session_name); + lttng_domain_type_str(dom.type), + channel_name, session_name); success = 1; } diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 0704b1475..948663412 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -25,6 +25,7 @@ /* Mi dependancy */ #include +#include #include #include "../command.h" @@ -486,7 +487,7 @@ static int enable_events(char *session_name) case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_PYTHON: ERR("Event name exclusions are not yet implemented for %s events", - get_domain_str(dom.type)); + lttng_domain_type_str(dom.type)); ret = CMD_ERROR; goto error; case LTTNG_DOMAIN_UST: @@ -656,7 +657,7 @@ static int enable_events(char *session_name) goto end; } MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), exclusion_string, print_channel_name(channel_name), opt_loglevel); @@ -670,7 +671,7 @@ static int enable_events(char *session_name) goto end; } MSG("All %s tracepoints%s are enabled in channel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), exclusion_string, print_channel_name(channel_name)); free(exclusion_string); @@ -679,7 +680,7 @@ static int enable_events(char *session_name) case LTTNG_EVENT_SYSCALL: if (opt_kernel) { MSG("All %s system calls are enabled in channel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), print_channel_name(channel_name)); } break; @@ -693,7 +694,7 @@ static int enable_events(char *session_name) goto end; } MSG("All %s events%s are enabled in channel %s for loglevel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), exclusion_string, print_channel_name(channel_name), opt_loglevel); @@ -707,7 +708,7 @@ static int enable_events(char *session_name) goto end; } MSG("All %s events%s are enabled in channel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), exclusion_string, print_channel_name(channel_name)); free(exclusion_string); @@ -1059,7 +1060,7 @@ static int enable_events(char *session_name) case LTTNG_DOMAIN_KERNEL: case LTTNG_DOMAIN_UST: MSG("%s event %s%s created in channel %s", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), event_name, exclusion_string, print_channel_name(channel_name)); @@ -1072,7 +1073,7 @@ static int enable_events(char *session_name) * name for agent domains. */ MSG("%s event %s%s enabled", - get_domain_str(dom.type), + lttng_domain_type_str(dom.type), event_name, exclusion_string); break; diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 4f4fcb5ef..34a9c8aa0 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "../command.h" @@ -576,7 +577,7 @@ static int list_agent_events(void) goto error; } - agent_domain_str = get_domain_str(domain.type); + agent_domain_str = lttng_domain_type_str(domain.type); DBG("Getting %s tracing events", agent_domain_str); diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index b363cfed0..e83694399 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -26,11 +26,6 @@ #include "utils.h" #include "command.h" -static const char *str_kernel = "Kernel"; -static const char *str_ust = "UST"; -static const char *str_jul = "JUL"; -static const char *str_log4j = "LOG4J"; -static const char *str_python = "Python"; static const char *str_all = "ALL"; static const char *str_tracepoint = "Tracepoint"; static const char *str_syscall = "Syscall"; @@ -298,34 +293,6 @@ int get_count_order_ulong(unsigned long x) return fls_ulong(x - 1); } -const char *get_domain_str(enum lttng_domain_type domain) -{ - const char *str_dom; - - switch (domain) { - case LTTNG_DOMAIN_KERNEL: - str_dom = str_kernel; - break; - case LTTNG_DOMAIN_UST: - str_dom = str_ust; - break; - case LTTNG_DOMAIN_JUL: - str_dom = str_jul; - break; - case LTTNG_DOMAIN_LOG4J: - str_dom = str_log4j; - break; - case LTTNG_DOMAIN_PYTHON: - str_dom = str_python; - break; - default: - /* Should not have an unknown domain or else define it. */ - assert(0); - } - - return str_dom; -} - const char *get_event_type_str(enum lttng_event_type type) { const char *str_event_type; diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index 97fb202ba..ba893edda 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -45,7 +45,6 @@ int get_count_order_u64(uint64_t x); */ int get_count_order_ulong(unsigned long x); -const char *get_domain_str(enum lttng_domain_type domain); const char *get_event_type_str(enum lttng_event_type event_type); int print_missing_or_multiple_domains(unsigned int domain_count, diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index aaca5946c..663d38a7d 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -710,7 +710,6 @@ const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val) LTTNG_HIDDEN const char *mi_lttng_domaintype_string(enum lttng_domain_type value) { - /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */ switch (value) { case LTTNG_DOMAIN_KERNEL: return config_domain_type_kernel; -- 2.34.1 From ecd27e604991b4d1d59167f62e8fd04441705544 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 16 Jul 2021 14:42:24 -0400 Subject: [PATCH 13/16] liblttng-ctl: hide MI trigger command variables MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau Change-Id: I45eec5bb0fd3353c8f1257b3c94ef08440114b21 --- src/common/mi-lttng.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index 7fbf7b53e..38a7d0d91 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -61,7 +61,7 @@ struct mi_lttng_error_query_callbacks { extern const char * const mi_lttng_element_command; extern const char * const mi_lttng_element_command_action; extern const char * const mi_lttng_element_command_add_context; -extern const char *const mi_lttng_element_command_add_trigger; +LTTNG_HIDDEN extern const char * const mi_lttng_element_command_add_trigger; extern const char * const mi_lttng_element_command_create; extern const char * const mi_lttng_element_command_destroy; extern const char * const mi_lttng_element_command_disable_channel; @@ -69,7 +69,7 @@ extern const char * const mi_lttng_element_command_disable_event; extern const char * const mi_lttng_element_command_enable_channels; extern const char * const mi_lttng_element_command_enable_event; extern const char * const mi_lttng_element_command_list; -extern const char *const mi_lttng_element_command_list_trigger; +LTTNG_HIDDEN extern const char * const mi_lttng_element_command_list_trigger; extern const char * const mi_lttng_element_command_load; extern const char * const mi_lttng_element_command_metadata; extern const char * const mi_lttng_element_command_metadata_action; @@ -77,7 +77,7 @@ extern const char * const mi_lttng_element_command_regenerate; extern const char * const mi_lttng_element_command_regenerate_action; extern const char * const mi_lttng_element_command_name; extern const char * const mi_lttng_element_command_output; -extern const char *const mi_lttng_element_command_remove_trigger; +LTTNG_HIDDEN extern const char * const mi_lttng_element_command_remove_trigger; extern const char * const mi_lttng_element_command_save; extern const char * const mi_lttng_element_command_set_session; extern const char * const mi_lttng_element_command_snapshot; -- 2.34.1 From 404efb6cc82ce08227b8c4ed0fe00fca7850349e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 16 Jul 2021 14:47:53 -0400 Subject: [PATCH 14/16] liblttng-ctl: hide logger_thread_name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau Change-Id: I4eb5a86029c6220ad4f48d382ec26126fd82e443 --- src/common/error.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/error.h b/src/common/error.h index 8af989e04..b43ec661b 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -44,7 +44,7 @@ struct log_time { char str[19]; }; extern DECLARE_URCU_TLS(struct log_time, error_log_time); -extern DECLARE_URCU_TLS(const char *, logger_thread_name); +extern LTTNG_HIDDEN DECLARE_URCU_TLS(const char *, logger_thread_name); extern int lttng_opt_quiet; extern int lttng_opt_verbose; -- 2.34.1 From c6ee68ae5269d3bcc28c884b17fb42b0e932877f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 16 Jul 2021 14:57:49 -0400 Subject: [PATCH 15/16] Update version to v2.13.0-rc3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- ChangeLog | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 21265991b..7671c0539 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,123 @@ +2021-07-16 lttng-tools 2.13.0-rc3 (World Snake Day) + * liblttng-ctl: hide logger_thread_name + * liblttng-ctl: hide MI trigger command variables + * Cleanup: rename `get_domain_str()` -> `lttng_domain_type_str()` + * .gitignore: Add hidden trigger test + * Test: unix socket: test credential passing + * Build fix: retrieve unix socket peer PID on non-unix platforms + * Fix: sessiond: notification: find_tracer_event_source returns NULL + * Tests: MI: add `diag` statements to test functions + * Cleanup: fix comments in `duplicate_{stream,channel}_object()` + * Tests: add hidden trigger visibility test + * Fix: sessiond: list-triggers: don't return internal triggers + * unix: receive pid on non-linux platforms + * Clean-up: sessiond: return an lttng_error_code from list_triggers + * notification-thread: remove fd from pollset on LPOLLHUP and friends + * Tests: fix: list triggers: bc missing on system + * Clean-up: event-expr: remove unreachable code + * Fix: lttng: remove-trigger: null dereference on MI initialization error + * Fix: lttng: list-trigger: leak of error query in query callbacks + * Fix: lttng: add-trigger: null dereference on MI initialization error + * lttng: add-trigger: print generated trigger name + * sessiond: generate trigger name: name triggers with the 'trigger' prefix + * Revert "lttng: add-trigger: print generated trigger name" + * lttng: add-trigger: print generated trigger name + * MI: xsd: bump to 4.1 + * Tests: trigger: mi: use utils.sh xsd versions for xml diff + * Tests: utils: regroup xml utils to utils.sh + * Tests: MI: {add, list, remove}-trigger + * MI: xsd: add objects type definition related to trigger + * MI: xsd: sort output_type + * MI: xsd: sort command_string_type + * Add pretty_xml utils + * Move xml utils from mi subfolder to xml-utils folder + * Fix: lttng_triggers count is not equal to the size of the sorted trigger array + * MI: {add, list, remove} trigger + * MI: implement all objects related to trigger machine interface + * Move event-expr-to-bytecode to event-expr + * Move event-expr from liblttng-ctl to libcommon + * MI: support double element + * Fix: rotation client example: leak of handle on error + * Silence warnings on GCC 4.8 with -Wmaybe-uninitialized + * doc/man/common-footer.txt: add missing non-breaking space + * Rename "tracing session" -> "recording session" + * doc/man: use double quotes when referring to internal section + * doc/man: update type/domain options for common event rule spec. + * .gitreview: Set default branch to 'stable-2.13' + * Fix: use of uninitialised bytes valgrind warning + * Fix: build: libcommon fd-tracker dependency is not available + * Clean-up: mark lttng_error_query communication header as const + * Add condition-targeting error query + * action list: missing renames from previous name "group" + * Cleanup: ust-app: simplify ust_app_synchronize() error paths + * Fix: double mutex_unlock() if session is deleted + * Fix: out of sync lttng_ust_ctl_sigbug_handle() prototype + * Fix: appending unallocated data from beyond exclusion entries + * Tests: remove leftover temporary files + * lttng-disable-channel(1): fix typo + * lttng-concepts(7): remove reference to the section it's in + * lttng-concepts(7): fix typo + * Build fix: build without lttng-ust + * build: Add missing DEFINE_LTTNG_UST_SIGBUS_STATE(); + * build: Pass --no-as-needed directly to the linker + * build: Use liblttng-sessiond-common.la instead of LIVE + * build: Use liblttng-sessiond-common.la instead of SESSIOND_OBJS + * build: Add the liblttng-sessiond-comm.la convenience library + * lttng-concepts(7): add missing "commands" word + * Tests: crash: remove redundant directory test + * Fix: bump minimal urcu dependency to 0.11 + * condition: buffer usage: validation does not check for ratio and bytes threshold + * Remove LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION + * Remove lttng_event_rule_tracepoint + * Test log level for newly introduced event rule type (*_logging, user_tracepoint) + * Introduce lttng_event_rule_python_logging + * Introduce lttng_event_rule_log4j_logging + * Introduce lttng_event_rule_jul_logging + * Introduce lttng_event_rule_user_tracepoint + * Introduce lttng_event_rule_kernel_tracepoint + * Rename lttng_event_rule_kernel_probe to lttng_event_rule_kernel_kprobe + * Rename lttng_event_rule_userspace_probe to lttng_event_rule_kernel_uprobe + * Rename lttng_event_rule_syscall to lttng_event_rule_kernel_syscall + * Rename *emission_site_type to *emission_site + * Rename lttng_event_rule_syscall_(set, get)_pattern to lttng_event_rule_syscall_(set, get)_name_pattern + * Rename *exclusion* to *name_pattern_exclusion* + * Rename lttng_event_rule_tracepoint_(set,get)_pattern to lttng_event_rule_tracepoint_(set, get)_name_pattern + * Build fix: cygwin: unknown type ssize_t + * Fix: consumer: unbalanced RCU read-side lock on error + * lttng-enable-event(1): add usage examples + * lttng-{enable,disable}-event(1): document default channel limitation + * doc/man: log level prefixes are not required + * Fix: sessiond: use of uninitialized memory in buffer-usage condition + * lttng-ctl: use lttng_action_path to specify error query actions + * error-query: add lttng_action_path to express the location of an action + * tests: Move tap-driver.sh out of the autotools aux directory + * lttng-enable-channel(1): add usage examples + * lttng-view(1): add usage examples + * lttng-untrack(1): add usage examples + * lttng-untrack(1): follow the style of lttng-track(1) for the example + * lttng-track(1): add usage examples + * lttng-stop(1): add usage examples + * lttng-start(1): add usage examples + * lttng-snapshot(1): add usage examples + * lttng-save(1): add usage examples + * lttng-rotate(1): add usage examples + * lttng-remove-trigger(1): add usage examples + * lttng-regenerate(1): add usage examples + * lttng-load(1): add usage examples + * lttng-list(1): add usage examples + * lttng-enable-rotation(1): add usage examples + * lttng-disable-rotation(1): add usage examples + * lttng-disable-event(1): add usage examples + * lttng-disable-channel(1): add usage examples + * lttng-destroy(1): add usage examples + * lttng-create(1): add usage examples + * lttng-clear(1): add usage examples + * lttng-add-trigger(1): DESCRIPTION: move up the link to "EXAMPLES" + * lttng-add-context(1): EXAMPLES: add internal links to relevant options + * lttng-disable-event(1): `--tracepoint` option is not the default + * Cleanup: tests: name all temporary files to better identify leakage + * Cleanup: tests: use find's `-name` option instead of grep + 2021-05-14 lttng-tools 2.13.0-rc2 (National Dance Like a Chicken Day) * Fix: expected procname should not have -ust suffix * Fix: Tests: leftover temporary files after tests diff --git a/configure.ac b/configure.ac index ecc5ce429..00ee876b5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl SPDX-License-Identifier: GPL-2.0-only AC_PREREQ([2.64]) -AC_INIT([lttng-tools],[2.13.0-rc2],[jeremie.galarneau@efficios.com],[],[https://lttng.org]) +AC_INIT([lttng-tools],[2.13.0-rc3],[jeremie.galarneau@efficios.com],[],[https://lttng.org]) AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_AUX_DIR([config]) -- 2.34.1 From 99052642b2db3ee0fbe669e93099f9056c7ea05b Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 19 Jul 2021 16:25:53 -0400 Subject: [PATCH 16/16] SoW-2021-0002: Custom 2.13 for ust-lower-urcu integration test. Signed-off-by: Jonathan Rajotte Change-Id: Ic71c2124657c1780ec52a90a9511b32114a08852 --- tests/regression/Makefile.am | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index dac6f84e6..89e1781b5 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -29,17 +29,8 @@ TESTS = tools/base-path/test_ust \ tools/crash/test_crash \ tools/regen-metadata/test_ust \ tools/regen-statedump/test_ust \ - tools/notification/test_notification_ust_error \ tools/notification/test_notification_ust_buffer_usage \ - tools/notification/test_notification_ust_capture \ - tools/notification/test_notification_ust_event_rule_condition_exclusion \ - tools/notification/test_notification_kernel_error \ tools/notification/test_notification_kernel_buffer_usage \ - tools/notification/test_notification_kernel_capture \ - tools/notification/test_notification_kernel_instrumentation \ - tools/notification/test_notification_kernel_syscall \ - tools/notification/test_notification_notifier_discarded_count \ - tools/notification/test_notification_kernel_userspace_probe \ tools/notification/test_notification_multi_app \ tools/rotation/test_ust \ tools/rotation/test_kernel \ @@ -48,13 +39,7 @@ TESTS = tools/base-path/test_ust \ tools/metadata/test_kernel \ tools/working-directory/test_relayd_working_directory \ tools/clear/test_ust \ - tools/clear/test_kernel \ - tools/tracker/test_event_tracker \ - tools/trigger/start-stop/test_start_stop \ - tools/trigger/test_add_trigger_cli \ - tools/trigger/test_list_triggers_cli \ - tools/trigger/test_remove_trigger_cli \ - tools/trigger/name/test_trigger_name_backwards_compat \ + tools/clear/test_kernel tools/trigger/hidden/test_hidden_trigger if HAVE_LIBLTTNG_UST_CTL @@ -76,8 +61,7 @@ TESTS += ust/before-after/test_before_after \ ust/multi-lib/test_multi_lib \ ust/rotation-destroy-flush/test_rotation_destroy_flush \ tools/metadata/test_ust \ - tools/relayd-grouping/test_ust \ - tools/trigger/rate-policy/test_ust_rate_policy + tools/relayd-grouping/test_ust if IS_LINUX TESTS += \ -- 2.34.1