+ /*
+ * For the JUL domain, a filter is enforced except for the
+ * disable all event. This is done to avoid having the event in
+ * all sessions thus filtering by logger name.
+ */
+ if (filter_expression == NULL &&
+ (handle->domain.type != LTTNG_DOMAIN_JUL &&
+ handle->domain.type != LTTNG_DOMAIN_LOG4J)) {
+ goto ask_sessiond;
+ }
+
+ /*
+ * We have a filter, so we need to set up a variable-length
+ * memory block from where to send the data.
+ */
+
+ /* Parse filter expression */
+ if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL
+ || handle->domain.type == LTTNG_DOMAIN_LOG4J) {
+ if (handle->domain.type == LTTNG_DOMAIN_JUL ||
+ handle->domain.type == LTTNG_DOMAIN_LOG4J) {
+ char *jul_filter;
+
+ /* Setup JUL filter if needed. */
+ jul_filter = set_jul_filter(filter_expression, ev);
+ if (!jul_filter) {
+ if (!filter_expression) {
+ /* No JUL and no filter, just skip everything below. */
+ goto ask_sessiond;
+ }
+ } else {
+ /*
+ * With a JUL filter, the original filter has been added to it
+ * thus replace the filter expression.
+ */
+ filter_expression = jul_filter;
+ free_filter_expression = 1;
+ }
+ }
+
+ ret = generate_filter(filter_expression, &lsm, &ctx);
+ if (ret) {
+ goto filter_error;
+ }
+ }
+
+ varlen_data = zmalloc(lsm.u.disable.bytecode_len
+ + lsm.u.disable.expression_len);
+ if (!varlen_data) {
+ ret = -LTTNG_ERR_EXCLUSION_NOMEM;
+ goto mem_error;
+ }
+
+ /* Add filter expression */
+ if (lsm.u.disable.expression_len != 0) {
+ memcpy(varlen_data,
+ filter_expression,
+ lsm.u.disable.expression_len);
+ }
+ /* Add filter bytecode next */
+ if (ctx && lsm.u.disable.bytecode_len != 0) {
+ memcpy(varlen_data
+ + lsm.u.disable.expression_len,
+ &ctx->bytecode->b,
+ lsm.u.disable.bytecode_len);
+ }
+
+ ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data,
+ lsm.u.disable.bytecode_len + lsm.u.disable.expression_len, NULL);
+ free(varlen_data);
+
+mem_error:
+ if (filter_expression && ctx) {
+ filter_bytecode_free(ctx);
+ filter_ir_free(ctx);
+ filter_parser_ctx_free(ctx);
+ }
+filter_error:
+ if (free_filter_expression) {
+ /*
+ * The filter expression has been replaced and must be freed as it is
+ * not the original filter expression received as a parameter.
+ */
+ free(filter_expression);
+ }
+error:
+ /*
+ * Return directly to the caller and don't ask the sessiond since something
+ * went wrong in the parsing of data above.
+ */
+ return ret;
+
+ask_sessiond:
+ ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ return ret;
+}
+
+/*
+ * Disable event(s) of a channel and domain.
+ * If no event name is specified, all events are disabled.
+ * If no channel name is specified, the default 'channel0' is used.
+ * Returns size of returned session payload data or a negative error code.
+ */
+int lttng_disable_event(struct lttng_handle *handle, const char *name,
+ const char *channel_name)
+{
+ struct lttng_event ev;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.type = LTTNG_EVENT_ALL;
+ lttng_ctl_copy_string(ev.name, name, sizeof(ev.name));
+ return lttng_disable_event_ext(handle, &ev, channel_name, NULL);