LTTNG_HIDDEN
void cleanup_kernel_tracer(void)
{
- int ret;
- struct cds_lfht_iter iter;
- struct ltt_kernel_event_notifier_rule *rule = NULL;
-
- rcu_read_lock();
- cds_lfht_for_each_entry(kernel_token_to_event_notifier_rule_ht, &iter, rule, ht_node) {
- kernel_disable_event_notifier_rule(rule);
- trace_kernel_destroy_event_notifier_rule(rule);
- }
- rcu_read_unlock();
-
DBG2("Closing kernel event notifier group notification file descriptor");
if (kernel_tracer_event_notifier_group_notification_fd >= 0) {
- ret = notification_thread_command_remove_tracer_event_source(
+ int ret = notification_thread_command_remove_tracer_event_source(
notification_thread_handle,
kernel_tracer_event_notifier_group_notification_fd);
if (ret != LTTNG_OK) {
}
if (kernel_token_to_event_notifier_rule_ht) {
- ret = cds_lfht_destroy(kernel_token_to_event_notifier_rule_ht, NULL);
+ const int ret = cds_lfht_destroy(
+ kernel_token_to_event_notifier_rule_ht, NULL);
assert(ret == 0);
}
DBG2("Closing kernel event notifier group file descriptor");
if (kernel_tracer_event_notifier_group_fd >= 0) {
- ret = close(kernel_tracer_event_notifier_group_fd);
+ const int ret = close(kernel_tracer_event_notifier_group_fd);
+
if (ret) {
PERROR("Failed to close kernel event notifier group file descriptor: fd = %d",
kernel_tracer_event_notifier_group_fd);
DBG2("Closing kernel fd");
if (kernel_tracer_fd >= 0) {
- ret = close(kernel_tracer_fd);
+ const int ret = close(kernel_tracer_fd);
+
if (ret) {
PERROR("Failed to close kernel tracer file descriptor: fd = %d",
kernel_tracer_fd);
DBG("Destruction of all sessions completed");
}
+static void unregister_all_triggers(void)
+{
+ enum lttng_error_code ret_code;
+ enum lttng_trigger_status trigger_status;
+ struct lttng_triggers *triggers = NULL;
+ unsigned int trigger_count, i;
+ const struct lttng_credentials creds = {
+ .uid = LTTNG_OPTIONAL_INIT_VALUE(0),
+ };
+
+ DBG("Unregistering all triggers");
+
+ /*
+ * List all triggers as "root" since we wish to unregister all triggers.
+ */
+ ret_code = notification_thread_command_list_triggers(
+ notification_thread_handle, creds.uid.value, &triggers);
+ if (ret_code != LTTNG_OK) {
+ ERR("Failed to list triggers while unregistering all triggers");
+ goto end;
+ }
+
+ trigger_status = lttng_triggers_get_count(triggers, &trigger_count);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ for (i = 0; i < trigger_count; i++) {
+ enum lttng_error_code ret_code;
+ uid_t trigger_owner;
+ const char *trigger_name;
+ const struct lttng_trigger *trigger =
+ lttng_triggers_get_at_index(triggers, i);
+
+ assert(trigger);
+
+ trigger_status = lttng_trigger_get_owner_uid(
+ trigger, &trigger_owner);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ DBG("Unregistering trigger: trigger owner uid = %d, trigger name = '%s'",
+ (int) trigger_owner, trigger_name);
+
+ ret_code = cmd_unregister_trigger(
+ &creds, trigger, notification_thread_handle);
+ if (ret_code != LTTNG_OK) {
+ ERR("Failed to unregister trigger: trigger owner uid = %d, trigger name = '%s', error: '%s'",
+ (int) trigger_owner, trigger_name,
+ lttng_strerror(-ret_code));
+ /* Continue to unregister the remaining triggers. */
+ }
+ }
+end:
+ lttng_triggers_destroy(triggers);
+}
+
static int run_as_worker_post_fork_cleanup(void *data)
{
struct sessiond_config *sessiond_config = data;
destroy_all_sessions_and_wait();
+ /*
+ * At this point no new trigger can be registered (no sessions are
+ * running/rotating) and clients can't connect to the session daemon
+ * anymore. Unregister all triggers.
+ */
+ unregister_all_triggers();
+
if (register_apps_thread) {
lttng_thread_shutdown(register_apps_thread);
lttng_thread_put(register_apps_thread);
if (ust_app_ht_by_notify_sock) {
cds_lfht_for_each_entry(ust_app_ht_by_notify_sock->ht, &iter.iter, app,
notify_sock_n.node) {
- struct cds_lfht_node *node;
- struct ust_app *app;
-
- node = cds_lfht_iter_get_node(&iter.iter);
- if (!node) {
- continue;
- }
+ /*
+ * Assert that all notifiers are gone as all triggers
+ * are unregistered prior to this clean-up.
+ */
+ assert(lttng_ht_get_count(app->token_to_event_notifier_rule_ht) == 0);
- app = container_of(node, struct ust_app,
- notify_sock_n.node);
ust_app_notify_sock_unregister(app->notify_sock);
}
}