| 1 | /* |
| 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef CMD_H |
| 9 | #define CMD_H |
| 10 | |
| 11 | #include "context.hpp" |
| 12 | #include "ctl-utils.hpp" |
| 13 | #include "lttng-sessiond.hpp" |
| 14 | #include "lttng/tracker.h" |
| 15 | #include "session.hpp" |
| 16 | |
| 17 | #include <common/tracker.hpp> |
| 18 | |
| 19 | #include <lttng/kernel.h> |
| 20 | |
| 21 | struct notification_thread_handle; |
| 22 | struct lttng_dynamic_buffer; |
| 23 | |
| 24 | /* |
| 25 | * A callback (and associated user data) that should be run after a command |
| 26 | * has been executed. No locks should be taken while executing this handler. |
| 27 | * |
| 28 | * The command's reply should not be sent until the handler has run and |
| 29 | * completed successfully. On failure, the handler's return code should |
| 30 | * be the only reply sent to the client. |
| 31 | */ |
| 32 | using completion_handler_function = enum lttng_error_code (*)(void *); |
| 33 | struct cmd_completion_handler { |
| 34 | completion_handler_function run; |
| 35 | void *data; |
| 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Init the command subsystem. Must be called before using any of the functions |
| 40 | * above. This is called in the main() of the session daemon. |
| 41 | */ |
| 42 | void cmd_init(); |
| 43 | |
| 44 | /* Session commands */ |
| 45 | enum lttng_error_code cmd_create_session(struct command_ctx *cmd_ctx, |
| 46 | int sock, |
| 47 | struct lttng_session_descriptor **return_descriptor); |
| 48 | int cmd_destroy_session(struct ltt_session *session, int *sock_fd); |
| 49 | |
| 50 | /* Channel commands */ |
| 51 | int cmd_disable_channel(struct ltt_session *session, |
| 52 | enum lttng_domain_type domain, |
| 53 | char *channel_name); |
| 54 | int cmd_enable_channel(struct command_ctx *cmd_ctx, |
| 55 | ltt_session::locked_ref& session, |
| 56 | int sock, |
| 57 | int wpipe); |
| 58 | |
| 59 | /* Process attribute tracker commands */ |
| 60 | enum lttng_error_code |
| 61 | cmd_process_attr_tracker_get_tracking_policy(struct ltt_session *session, |
| 62 | enum lttng_domain_type domain, |
| 63 | enum lttng_process_attr process_attr, |
| 64 | enum lttng_tracking_policy *policy); |
| 65 | enum lttng_error_code |
| 66 | cmd_process_attr_tracker_set_tracking_policy(struct ltt_session *session, |
| 67 | enum lttng_domain_type domain, |
| 68 | enum lttng_process_attr process_attr, |
| 69 | enum lttng_tracking_policy policy); |
| 70 | enum lttng_error_code |
| 71 | cmd_process_attr_tracker_inclusion_set_add_value(struct ltt_session *session, |
| 72 | enum lttng_domain_type domain, |
| 73 | enum lttng_process_attr process_attr, |
| 74 | const struct process_attr_value *value); |
| 75 | enum lttng_error_code |
| 76 | cmd_process_attr_tracker_inclusion_set_remove_value(struct ltt_session *session, |
| 77 | enum lttng_domain_type domain, |
| 78 | enum lttng_process_attr process_attr, |
| 79 | const struct process_attr_value *value); |
| 80 | enum lttng_error_code |
| 81 | cmd_process_attr_tracker_get_inclusion_set(struct ltt_session *session, |
| 82 | enum lttng_domain_type domain, |
| 83 | enum lttng_process_attr process_attr, |
| 84 | struct lttng_process_attr_values **values); |
| 85 | |
| 86 | /* Event commands */ |
| 87 | int cmd_disable_event(struct command_ctx *cmd_ctx, |
| 88 | ltt_session::locked_ref& locked_session, |
| 89 | struct lttng_event *event, |
| 90 | char *filter_expression, |
| 91 | struct lttng_bytecode *filter, |
| 92 | struct lttng_event_exclusion *exclusion); |
| 93 | int cmd_add_context(struct command_ctx *cmd_ctx, |
| 94 | ltt_session::locked_ref& locked_session, |
| 95 | const struct lttng_event_context *event_context, |
| 96 | int kwpipe); |
| 97 | int cmd_set_filter(struct ltt_session *session, |
| 98 | enum lttng_domain_type domain, |
| 99 | char *channel_name, |
| 100 | struct lttng_event *event, |
| 101 | struct lttng_bytecode *bytecode); |
| 102 | int cmd_enable_event(struct command_ctx *cmd_ctx, |
| 103 | ltt_session::locked_ref& session, |
| 104 | struct lttng_event *event, |
| 105 | char *filter_expression, |
| 106 | struct lttng_event_exclusion *exclusion, |
| 107 | struct lttng_bytecode *bytecode, |
| 108 | int wpipe); |
| 109 | |
| 110 | /* Trace session action commands */ |
| 111 | int cmd_start_trace(struct ltt_session *session); |
| 112 | int cmd_stop_trace(struct ltt_session *session); |
| 113 | |
| 114 | /* Consumer commands */ |
| 115 | int cmd_register_consumer(struct ltt_session *session, |
| 116 | enum lttng_domain_type domain, |
| 117 | const char *sock_path, |
| 118 | struct consumer_data *cdata); |
| 119 | int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, struct lttng_uri *uris); |
| 120 | int cmd_setup_relayd(struct ltt_session *session); |
| 121 | |
| 122 | /* Listing commands */ |
| 123 | ssize_t cmd_list_domains(struct ltt_session *session, struct lttng_domain **domains); |
| 124 | enum lttng_error_code cmd_list_events(enum lttng_domain_type domain, |
| 125 | struct ltt_session *session, |
| 126 | char *channel_name, |
| 127 | struct lttng_payload *payload); |
| 128 | enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain, |
| 129 | struct ltt_session *session, |
| 130 | struct lttng_payload *payload); |
| 131 | void cmd_list_lttng_sessions(struct lttng_session *sessions, |
| 132 | size_t session_count, |
| 133 | uid_t uid, |
| 134 | gid_t gid); |
| 135 | enum lttng_error_code cmd_list_tracepoint_fields(enum lttng_domain_type domain, |
| 136 | struct lttng_payload *reply); |
| 137 | enum lttng_error_code cmd_list_tracepoints(enum lttng_domain_type domain, |
| 138 | struct lttng_payload *reply_payload); |
| 139 | ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, |
| 140 | struct lttng_snapshot_output **outputs); |
| 141 | enum lttng_error_code cmd_list_syscalls(struct lttng_payload *reply_payload); |
| 142 | |
| 143 | int cmd_data_pending(struct ltt_session *session); |
| 144 | enum lttng_error_code cmd_kernel_tracer_status(enum lttng_kernel_tracer_status *status); |
| 145 | |
| 146 | /* Snapshot */ |
| 147 | int cmd_snapshot_add_output(struct ltt_session *session, |
| 148 | const struct lttng_snapshot_output *output, |
| 149 | uint32_t *id); |
| 150 | int cmd_snapshot_del_output(struct ltt_session *session, |
| 151 | const struct lttng_snapshot_output *output); |
| 152 | int cmd_snapshot_record(struct ltt_session *session, |
| 153 | const struct lttng_snapshot_output *output, |
| 154 | int wait); |
| 155 | |
| 156 | int cmd_set_session_shm_path(struct ltt_session *session, const char *shm_path); |
| 157 | int cmd_regenerate_metadata(struct ltt_session *session); |
| 158 | int cmd_regenerate_statedump(struct ltt_session *session); |
| 159 | |
| 160 | lttng::ctl::trigger |
| 161 | cmd_register_trigger(const struct lttng_credentials *cmd_creds, |
| 162 | struct lttng_trigger *trigger, |
| 163 | bool is_anonymous_trigger, |
| 164 | struct notification_thread_handle *notification_thread_handle); |
| 165 | enum lttng_error_code |
| 166 | cmd_unregister_trigger(const struct lttng_credentials *cmd_creds, |
| 167 | const struct lttng_trigger *trigger, |
| 168 | struct notification_thread_handle *notification_thread_handle); |
| 169 | |
| 170 | enum lttng_error_code |
| 171 | cmd_list_triggers(struct command_ctx *cmd_ctx, |
| 172 | struct notification_thread_handle *notification_thread_handle, |
| 173 | struct lttng_triggers **return_triggers); |
| 174 | enum lttng_error_code |
| 175 | cmd_execute_error_query(const struct lttng_credentials *cmd_creds, |
| 176 | const struct lttng_error_query *query, |
| 177 | struct lttng_error_query_results **_results, |
| 178 | struct notification_thread_handle *notification_thread); |
| 179 | |
| 180 | int cmd_rotate_session(struct ltt_session *session, |
| 181 | struct lttng_rotate_session_return *rotate_return, |
| 182 | bool quiet_rotation, |
| 183 | enum lttng_trace_chunk_command_type command); |
| 184 | int cmd_rotate_get_info(struct ltt_session *session, |
| 185 | struct lttng_rotation_get_info_return *info_return, |
| 186 | uint64_t rotate_id); |
| 187 | int cmd_rotation_set_schedule(struct ltt_session *session, |
| 188 | bool activate, |
| 189 | enum lttng_rotation_schedule_type schedule_type, |
| 190 | uint64_t value); |
| 191 | |
| 192 | const struct cmd_completion_handler *cmd_pop_completion_handler(); |
| 193 | int start_kernel_session(struct ltt_kernel_session *ksess); |
| 194 | int stop_kernel_session(struct ltt_kernel_session *ksess); |
| 195 | |
| 196 | #endif /* CMD_H */ |