125c871eaf80c98d63579713866d88339de4f760
[lttng-tools.git] / src / common / trigger.c
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include <lttng/trigger/trigger-internal.h>
9 #include <lttng/condition/condition-internal.h>
10 #include <lttng/condition/on-event-internal.h>
11 #include <lttng/condition/on-event.h>
12 #include <lttng/condition/on-event-internal.h>
13 #include <lttng/condition/buffer-usage.h>
14 #include <lttng/event-rule/event-rule-internal.h>
15 #include <lttng/event-expr-internal.h>
16 #include <lttng/action/action-internal.h>
17 #include <common/credentials.h>
18 #include <common/payload.h>
19 #include <common/payload-view.h>
20 #include <lttng/domain.h>
21 #include <common/error.h>
22 #include <common/dynamic-array.h>
23 #include <common/optional.h>
24 #include <assert.h>
25 #include <inttypes.h>
26
27 LTTNG_HIDDEN
28 bool lttng_trigger_validate(const struct lttng_trigger *trigger)
29 {
30 bool valid;
31
32 if (!trigger) {
33 valid = false;
34 goto end;
35 }
36
37 if (!trigger->creds.uid.is_set) {
38 valid = false;
39 goto end;
40 }
41
42 valid = lttng_condition_validate(trigger->condition) &&
43 lttng_action_validate(trigger->action);
44 end:
45 return valid;
46 }
47
48 struct lttng_trigger *lttng_trigger_create(
49 struct lttng_condition *condition,
50 struct lttng_action *action)
51 {
52 struct lttng_trigger *trigger = NULL;
53
54 if (!condition || !action) {
55 goto end;
56 }
57
58 trigger = zmalloc(sizeof(struct lttng_trigger));
59 if (!trigger) {
60 goto end;
61 }
62
63 urcu_ref_init(&trigger->ref);
64
65 lttng_condition_get(condition);
66 trigger->condition = condition;
67
68 lttng_action_get(action);
69 trigger->action = action;
70
71 end:
72 return trigger;
73 }
74
75 /*
76 * Note: the lack of reference counting 'get' on the condition object is normal.
77 * This API was exposed as such in 2.11. The client is not expected to call
78 * lttng_condition_destroy on the returned object.
79 */
80 struct lttng_condition *lttng_trigger_get_condition(
81 struct lttng_trigger *trigger)
82 {
83 return trigger ? trigger->condition : NULL;
84 }
85
86 const struct lttng_condition *lttng_trigger_get_const_condition(
87 const struct lttng_trigger *trigger)
88 {
89 return trigger ? trigger->condition : NULL;
90 }
91
92 /*
93 * Note: the lack of reference counting 'get' on the action object is normal.
94 * This API was exposed as such in 2.11. The client is not expected to call
95 * lttng_action_destroy on the returned object.
96 */
97 struct lttng_action *lttng_trigger_get_action(
98 struct lttng_trigger *trigger)
99 {
100 return trigger ? trigger->action : NULL;
101 }
102
103 const struct lttng_action *lttng_trigger_get_const_action(
104 const struct lttng_trigger *trigger)
105 {
106 return trigger ? trigger->action : NULL;
107 }
108
109 static void trigger_destroy_ref(struct urcu_ref *ref)
110 {
111 struct lttng_trigger *trigger =
112 container_of(ref, struct lttng_trigger, ref);
113 struct lttng_action *action = lttng_trigger_get_action(trigger);
114 struct lttng_condition *condition =
115 lttng_trigger_get_condition(trigger);
116
117 assert(action);
118 assert(condition);
119
120 /* Release ownership. */
121 lttng_action_put(action);
122 lttng_condition_put(condition);
123
124 free(trigger->name);
125 free(trigger);
126 }
127
128 void lttng_trigger_destroy(struct lttng_trigger *trigger)
129 {
130 lttng_trigger_put(trigger);
131 }
132
133 LTTNG_HIDDEN
134 ssize_t lttng_trigger_create_from_payload(
135 struct lttng_payload_view *src_view,
136 struct lttng_trigger **_trigger)
137 {
138 ssize_t ret, offset = 0, condition_size, action_size, name_size = 0;
139 struct lttng_condition *condition = NULL;
140 struct lttng_action *action = NULL;
141 const struct lttng_trigger_comm *trigger_comm;
142 const char *name = NULL;
143 struct lttng_credentials creds = {
144 .uid = LTTNG_OPTIONAL_INIT_UNSET,
145 .gid = LTTNG_OPTIONAL_INIT_UNSET,
146 };
147 struct lttng_trigger *trigger = NULL;
148 const struct lttng_payload_view trigger_comm_view =
149 lttng_payload_view_from_view(
150 src_view, 0, sizeof(*trigger_comm));
151
152 if (!src_view || !_trigger) {
153 ret = -1;
154 goto end;
155 }
156
157 if (!lttng_payload_view_is_valid(&trigger_comm_view)) {
158 /* Payload not large enough to contain the header. */
159 ret = -1;
160 goto end;
161 }
162
163 /* lttng_trigger_comm header */
164 trigger_comm = (typeof(trigger_comm)) trigger_comm_view.buffer.data;
165
166 /* Set the trigger's creds. */
167 if (trigger_comm->uid > (uint64_t) ((uid_t) -1)) {
168 /* UID out of range for this platform. */
169 ret = -1;
170 goto end;
171 }
172
173 LTTNG_OPTIONAL_SET(&creds.uid, trigger_comm->uid);
174
175 offset += sizeof(*trigger_comm);
176
177 if (trigger_comm->name_length != 0) {
178 /* Name. */
179 const struct lttng_payload_view name_view =
180 lttng_payload_view_from_view(
181 src_view, offset,
182 trigger_comm->name_length);
183
184 if (!lttng_payload_view_is_valid(&name_view)) {
185 ret = -1;
186 goto end;
187 }
188
189 name = name_view.buffer.data;
190 if (!lttng_buffer_view_contains_string(&name_view.buffer, name,
191 trigger_comm->name_length)) {
192 ret = -1;
193 goto end;
194 }
195
196 offset += trigger_comm->name_length;
197 name_size = trigger_comm->name_length;
198 }
199
200 {
201 /* struct lttng_condition */
202 struct lttng_payload_view condition_view =
203 lttng_payload_view_from_view(
204 src_view, offset, -1);
205
206 condition_size = lttng_condition_create_from_payload(&condition_view,
207 &condition);
208 }
209
210 if (condition_size < 0) {
211 ret = condition_size;
212 goto end;
213 }
214
215 offset += condition_size;
216 {
217 /* struct lttng_action */
218 struct lttng_payload_view action_view =
219 lttng_payload_view_from_view(
220 src_view, offset, -1);
221
222 action_size = lttng_action_create_from_payload(&action_view, &action);
223 }
224
225 if (action_size < 0) {
226 ret = action_size;
227 goto end;
228 }
229 offset += action_size;
230
231 /* Unexpected size of inner-elements; the buffer is corrupted. */
232 if ((ssize_t) trigger_comm->length != condition_size + action_size + name_size) {
233 ret = -1;
234 goto error;
235 }
236
237 trigger = lttng_trigger_create(condition, action);
238 if (!trigger) {
239 ret = -1;
240 goto error;
241 }
242
243 lttng_trigger_set_credentials(trigger, &creds);
244
245 /*
246 * The trigger object owns references to the action and condition
247 * objects.
248 */
249 lttng_condition_put(condition);
250 condition = NULL;
251
252 lttng_action_put(action);
253 action = NULL;
254
255 if (name) {
256 const enum lttng_trigger_status status =
257 lttng_trigger_set_name(trigger, name);
258
259 if (status != LTTNG_TRIGGER_STATUS_OK) {
260 ret = -1;
261 goto end;
262 }
263 }
264
265 ret = offset;
266
267 error:
268 lttng_condition_put(condition);
269 lttng_action_put(action);
270 end:
271 if (ret >= 0) {
272 *_trigger = trigger;
273 } else {
274 lttng_trigger_put(trigger);
275 }
276
277 return ret;
278 }
279
280 /*
281 * Both elements are stored contiguously, see their "*_comm" structure
282 * for the detailed format.
283 */
284 LTTNG_HIDDEN
285 int lttng_trigger_serialize(const struct lttng_trigger *trigger,
286 struct lttng_payload *payload)
287 {
288 int ret;
289 size_t header_offset, size_before_payload, size_name;
290 struct lttng_trigger_comm trigger_comm = {};
291 struct lttng_trigger_comm *header;
292 const struct lttng_credentials *creds = NULL;
293
294 creds = lttng_trigger_get_credentials(trigger);
295 assert(creds);
296
297 trigger_comm.uid = LTTNG_OPTIONAL_GET(creds->uid);
298
299 if (trigger->name != NULL) {
300 size_name = strlen(trigger->name) + 1;
301 } else {
302 size_name = 0;
303 }
304
305 trigger_comm.name_length = size_name;
306
307 header_offset = payload->buffer.size;
308 ret = lttng_dynamic_buffer_append(&payload->buffer, &trigger_comm,
309 sizeof(trigger_comm));
310 if (ret) {
311 goto end;
312 }
313
314 size_before_payload = payload->buffer.size;
315
316 /* Trigger name. */
317 ret = lttng_dynamic_buffer_append(
318 &payload->buffer, trigger->name, size_name);
319 if (ret) {
320 goto end;
321 }
322
323 ret = lttng_condition_serialize(trigger->condition, payload);
324 if (ret) {
325 goto end;
326 }
327
328 ret = lttng_action_serialize(trigger->action, payload);
329 if (ret) {
330 goto end;
331 }
332
333 /* Update payload size. */
334 header = (typeof(header)) (payload->buffer.data + header_offset);
335 header->length = payload->buffer.size - size_before_payload;
336 end:
337 return ret;
338 }
339
340 LTTNG_HIDDEN
341 bool lttng_trigger_is_equal(
342 const struct lttng_trigger *a, const struct lttng_trigger *b)
343 {
344 if (strcmp(a->name, b->name) != 0) {
345 return false;
346 }
347
348 if (!lttng_condition_is_equal(a->condition, b->condition)) {
349 return false;
350 }
351
352 if (!lttng_action_is_equal(a->action, b->action)) {
353 return false;
354 }
355
356 if (!lttng_credentials_is_equal(lttng_trigger_get_credentials(a),
357 lttng_trigger_get_credentials(b))) {
358 return false;
359 }
360
361 return true;
362 }
363
364 enum lttng_trigger_status lttng_trigger_set_name(struct lttng_trigger *trigger,
365 const char* name)
366 {
367 char *name_copy = NULL;
368 enum lttng_trigger_status status = LTTNG_TRIGGER_STATUS_OK;
369
370 if (!trigger || !name ||
371 strlen(name) == 0) {
372 status = LTTNG_TRIGGER_STATUS_INVALID;
373 goto end;
374 }
375
376 name_copy = strdup(name);
377 if (!name_copy) {
378 status = LTTNG_TRIGGER_STATUS_ERROR;
379 goto end;
380 }
381
382 free(trigger->name);
383
384 trigger->name = name_copy;
385 name_copy = NULL;
386 end:
387 return status;
388 }
389
390 enum lttng_trigger_status lttng_trigger_get_name(
391 const struct lttng_trigger *trigger, const char **name)
392 {
393 enum lttng_trigger_status status = LTTNG_TRIGGER_STATUS_OK;
394
395 if (!trigger || !name) {
396 status = LTTNG_TRIGGER_STATUS_INVALID;
397 goto end;
398 }
399
400 if (!trigger->name) {
401 status = LTTNG_TRIGGER_STATUS_UNSET;
402 }
403
404 *name = trigger->name;
405 end:
406 return status;
407 }
408
409 LTTNG_HIDDEN
410 int lttng_trigger_assign_name(struct lttng_trigger *dst,
411 const struct lttng_trigger *src)
412 {
413 int ret = 0;
414 enum lttng_trigger_status status;
415
416 status = lttng_trigger_set_name(dst, src->name);
417 if (status != LTTNG_TRIGGER_STATUS_OK) {
418 ret = -1;
419 ERR("Failed to set name for trigger");
420 goto end;
421 }
422 end:
423 return ret;
424 }
425
426 LTTNG_HIDDEN
427 void lttng_trigger_set_tracer_token(struct lttng_trigger *trigger,
428 uint64_t token)
429 {
430 assert(trigger);
431 LTTNG_OPTIONAL_SET(&trigger->tracer_token, token);
432 }
433
434 LTTNG_HIDDEN
435 uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger)
436 {
437 assert(trigger);
438
439 return LTTNG_OPTIONAL_GET(trigger->tracer_token);
440 }
441
442 LTTNG_HIDDEN
443 int lttng_trigger_generate_name(struct lttng_trigger *trigger,
444 uint64_t unique_id)
445 {
446 int ret = 0;
447 char *generated_name = NULL;
448
449 ret = asprintf(&generated_name, "T%" PRIu64 "", unique_id);
450 if (ret < 0) {
451 ERR("Failed to generate trigger name");
452 ret = -1;
453 goto end;
454 }
455
456 ret = 0;
457 free(trigger->name);
458 trigger->name = generated_name;
459 end:
460 return ret;
461 }
462
463 LTTNG_HIDDEN
464 void lttng_trigger_get(struct lttng_trigger *trigger)
465 {
466 urcu_ref_get(&trigger->ref);
467 }
468
469 LTTNG_HIDDEN
470 void lttng_trigger_put(struct lttng_trigger *trigger)
471 {
472 if (!trigger) {
473 return;
474 }
475
476 urcu_ref_put(&trigger->ref , trigger_destroy_ref);
477 }
478
479 static void delete_trigger_array_element(void *ptr)
480 {
481 struct lttng_trigger *trigger = ptr;
482
483 lttng_trigger_put(trigger);
484 }
485
486 LTTNG_HIDDEN
487 struct lttng_triggers *lttng_triggers_create(void)
488 {
489 struct lttng_triggers *triggers = NULL;
490
491 triggers = zmalloc(sizeof(*triggers));
492 if (!triggers) {
493 goto end;
494 }
495
496 lttng_dynamic_pointer_array_init(&triggers->array, delete_trigger_array_element);
497
498 end:
499 return triggers;
500 }
501
502 LTTNG_HIDDEN
503 struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
504 const struct lttng_triggers *triggers, unsigned int index)
505 {
506 struct lttng_trigger *trigger = NULL;
507
508 assert(triggers);
509 if (index >= lttng_dynamic_pointer_array_get_count(&triggers->array)) {
510 goto end;
511 }
512
513 trigger = (struct lttng_trigger *)
514 lttng_dynamic_pointer_array_get_pointer(
515 &triggers->array, index);
516 end:
517 return trigger;
518 }
519
520 LTTNG_HIDDEN
521 int lttng_triggers_add(
522 struct lttng_triggers *triggers, struct lttng_trigger *trigger)
523 {
524 int ret;
525
526 assert(triggers);
527 assert(trigger);
528
529 lttng_trigger_get(trigger);
530
531 ret = lttng_dynamic_pointer_array_add_pointer(&triggers->array, trigger);
532 if (ret) {
533 lttng_trigger_put(trigger);
534 }
535
536 return ret;
537 }
538
539 const struct lttng_trigger *lttng_triggers_get_at_index(
540 const struct lttng_triggers *triggers, unsigned int index)
541 {
542 return lttng_triggers_borrow_mutable_at_index(triggers, index);
543 }
544
545 enum lttng_trigger_status lttng_triggers_get_count(const struct lttng_triggers *triggers, unsigned int *count)
546 {
547 enum lttng_trigger_status status = LTTNG_TRIGGER_STATUS_OK;
548
549 if (!triggers || !count) {
550 status = LTTNG_TRIGGER_STATUS_INVALID;
551 goto end;
552 }
553
554 *count = lttng_dynamic_pointer_array_get_count(&triggers->array);
555 end:
556 return status;
557 }
558
559 void lttng_triggers_destroy(struct lttng_triggers *triggers)
560 {
561 if (!triggers) {
562 return;
563 }
564
565 lttng_dynamic_pointer_array_reset(&triggers->array);
566 free(triggers);
567 }
568
569 int lttng_triggers_serialize(const struct lttng_triggers *triggers,
570 struct lttng_payload *payload)
571 {
572 int ret;
573 unsigned int i, count;
574 size_t size_before_payload;
575 struct lttng_triggers_comm triggers_comm = {};
576 struct lttng_triggers_comm *header;
577 enum lttng_trigger_status status;
578 const size_t header_offset = payload->buffer.size;
579
580 status = lttng_triggers_get_count(triggers, &count);
581 if (status != LTTNG_TRIGGER_STATUS_OK) {
582 ret = LTTNG_ERR_INVALID;
583 goto end;
584 }
585
586 triggers_comm.count = count;
587
588 /* Placeholder header; updated at the end. */
589 ret = lttng_dynamic_buffer_append(&payload->buffer, &triggers_comm,
590 sizeof(triggers_comm));
591 if (ret) {
592 goto end;
593 }
594
595 size_before_payload = payload->buffer.size;
596
597 for (i = 0; i < count; i++) {
598 const struct lttng_trigger *trigger =
599 lttng_triggers_get_at_index(triggers, i);
600
601 assert(trigger);
602
603 ret = lttng_trigger_serialize(trigger, payload);
604 if (ret) {
605 goto end;
606 }
607 }
608
609 /* Update payload size. */
610 header = (struct lttng_triggers_comm *) ((char *) payload->buffer.data + header_offset);
611 header->length = payload->buffer.size - size_before_payload;
612 end:
613 return ret;
614 }
615
616 LTTNG_HIDDEN
617 ssize_t lttng_triggers_create_from_payload(
618 struct lttng_payload_view *src_view,
619 struct lttng_triggers **triggers)
620 {
621 ssize_t ret, offset = 0, triggers_size = 0;
622 unsigned int i;
623 const struct lttng_triggers_comm *triggers_comm;
624 struct lttng_triggers *local_triggers = NULL;
625
626 if (!src_view || !triggers) {
627 ret = -1;
628 goto error;
629 }
630
631 /* lttng_trigger_comms header */
632 triggers_comm = (const struct lttng_triggers_comm *) src_view->buffer.data;
633 offset += sizeof(*triggers_comm);
634
635 local_triggers = lttng_triggers_create();
636 if (!local_triggers) {
637 ret = -1;
638 goto error;
639 }
640
641 for (i = 0; i < triggers_comm->count; i++) {
642 struct lttng_trigger *trigger = NULL;
643 struct lttng_payload_view trigger_view =
644 lttng_payload_view_from_view(src_view, offset, -1);
645 ssize_t trigger_size;
646
647 trigger_size = lttng_trigger_create_from_payload(
648 &trigger_view, &trigger);
649 if (trigger_size < 0) {
650 ret = trigger_size;
651 goto error;
652 }
653
654 /* Transfer ownership of the trigger to the collection. */
655 ret = lttng_triggers_add(local_triggers, trigger);
656 lttng_trigger_put(trigger);
657 if (ret < 0) {
658 ret = -1;
659 goto error;
660 }
661
662 offset += trigger_size;
663 triggers_size += trigger_size;
664 }
665
666 /* Unexpected size of inner-elements; the buffer is corrupted. */
667 if ((ssize_t) triggers_comm->length != triggers_size) {
668 ret = -1;
669 goto error;
670 }
671
672 /* Pass ownership to caller. */
673 *triggers = local_triggers;
674 local_triggers = NULL;
675
676 ret = offset;
677 error:
678
679 lttng_triggers_destroy(local_triggers);
680 return ret;
681 }
682
683 LTTNG_HIDDEN
684 const struct lttng_credentials *lttng_trigger_get_credentials(
685 const struct lttng_trigger *trigger)
686 {
687 return &trigger->creds;
688 }
689
690 LTTNG_HIDDEN
691 void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
692 const struct lttng_credentials *creds)
693 {
694 assert(creds);
695 trigger->creds = *creds;
696 }
697
698 enum lttng_trigger_status lttng_trigger_set_owner_uid(
699 struct lttng_trigger *trigger, uid_t uid)
700 {
701 enum lttng_trigger_status ret = LTTNG_TRIGGER_STATUS_OK;
702 const struct lttng_credentials creds = {
703 .uid = LTTNG_OPTIONAL_INIT_VALUE(uid),
704 .gid = LTTNG_OPTIONAL_INIT_UNSET,
705 };
706
707 if (!trigger) {
708 ret = LTTNG_TRIGGER_STATUS_INVALID;
709 goto end;
710 }
711
712 /* Client-side validation only to report a clearer error. */
713 if (geteuid() != 0) {
714 ret = LTTNG_TRIGGER_STATUS_PERMISSION_DENIED;
715 goto end;
716 }
717
718 lttng_trigger_set_credentials(trigger, &creds);
719
720 end:
721 return ret;
722 }
723
724 enum lttng_trigger_status lttng_trigger_get_owner_uid(
725 const struct lttng_trigger *trigger, uid_t *uid)
726 {
727 enum lttng_trigger_status ret = LTTNG_TRIGGER_STATUS_OK;
728 const struct lttng_credentials *creds = NULL;
729
730 if (!trigger || !uid ) {
731 ret = LTTNG_TRIGGER_STATUS_INVALID;
732 goto end;
733 }
734
735 if (!trigger->creds.uid.is_set ) {
736 ret = LTTNG_TRIGGER_STATUS_UNSET;
737 goto end;
738 }
739
740 creds = lttng_trigger_get_credentials(trigger);
741 *uid = lttng_credentials_get_uid(creds);
742
743 end:
744 return ret;
745 }
746
747 LTTNG_HIDDEN
748 enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
749 const struct lttng_trigger *trigger)
750 {
751 enum lttng_domain_type type = LTTNG_DOMAIN_NONE;
752 const struct lttng_event_rule *event_rule;
753 enum lttng_condition_status c_status;
754 enum lttng_condition_type c_type;
755
756 assert(trigger);
757 assert(trigger->condition);
758
759 c_type = lttng_condition_get_type(trigger->condition);
760 assert (c_type != LTTNG_CONDITION_TYPE_UNKNOWN);
761
762 switch (c_type) {
763 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
764 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
765 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
766 /* Apply to any domain. */
767 type = LTTNG_DOMAIN_NONE;
768 break;
769 case LTTNG_CONDITION_TYPE_ON_EVENT:
770 /* Return the domain of the event rule. */
771 c_status = lttng_condition_on_event_get_rule(
772 trigger->condition, &event_rule);
773 assert(c_status == LTTNG_CONDITION_STATUS_OK);
774 type = lttng_event_rule_get_domain_type(event_rule);
775 break;
776 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
777 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
778 /* Return the domain of the channel being monitored. */
779 c_status = lttng_condition_buffer_usage_get_domain_type(
780 trigger->condition, &type);
781 assert(c_status == LTTNG_CONDITION_STATUS_OK);
782 break;
783 default:
784 abort();
785 }
786
787 return type;
788 }
789
790 /*
791 * Generate bytecode related to the trigger.
792 * On success LTTNG_OK. On error, returns lttng_error code.
793 */
794 LTTNG_HIDDEN
795 enum lttng_error_code lttng_trigger_generate_bytecode(
796 struct lttng_trigger *trigger,
797 const struct lttng_credentials *creds)
798 {
799 enum lttng_error_code ret;
800 struct lttng_condition *condition = NULL;
801
802 condition = lttng_trigger_get_condition(trigger);
803 if (!condition) {
804 ret = LTTNG_ERR_INVALID_TRIGGER;
805 goto end;
806 }
807
808 switch (lttng_condition_get_type(condition)) {
809 case LTTNG_CONDITION_TYPE_ON_EVENT:
810 {
811 struct lttng_event_rule *event_rule;
812 const enum lttng_condition_status condition_status =
813 lttng_condition_on_event_borrow_rule_mutable(
814 condition, &event_rule);
815
816 assert(condition_status == LTTNG_CONDITION_STATUS_OK);
817
818 /* Generate the filter bytecode. */
819 ret = lttng_event_rule_generate_filter_bytecode(
820 event_rule, creds);
821 if (ret != LTTNG_OK) {
822 goto end;
823 }
824
825 /* Generate the capture bytecode. */
826 ret = lttng_condition_on_event_generate_capture_descriptor_bytecode(
827 condition);
828 if (ret != LTTNG_OK) {
829 goto end;
830 }
831
832 ret = LTTNG_OK;
833 break;
834 }
835 default:
836 ret = LTTNG_OK;
837 break;
838 }
839 end:
840 return ret;
841 }
842
843 LTTNG_HIDDEN
844 struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger)
845 {
846 int ret;
847 struct lttng_payload copy_buffer;
848 struct lttng_trigger *copy = NULL;
849
850 lttng_payload_init(&copy_buffer);
851
852 ret = lttng_trigger_serialize(trigger, &copy_buffer);
853 if (ret < 0) {
854 goto end;
855 }
856
857 {
858 struct lttng_payload_view view =
859 lttng_payload_view_from_payload(
860 &copy_buffer, 0, -1);
861 ret = lttng_trigger_create_from_payload(
862 &view, &copy);
863 if (ret < 0) {
864 copy = NULL;
865 goto end;
866 }
867 }
868
869 end:
870 lttng_payload_reset(&copy_buffer);
871 return copy;
872 }
873
874 LTTNG_HIDDEN
875 bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger)
876 {
877 bool needs_tracer_notifier = false;
878 const struct lttng_condition *condition =
879 lttng_trigger_get_const_condition(trigger);
880
881 switch (lttng_condition_get_type(condition)) {
882 case LTTNG_CONDITION_TYPE_ON_EVENT:
883 needs_tracer_notifier = true;
884 goto end;
885 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
886 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
887 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
888 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
889 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
890 goto end;
891 case LTTNG_CONDITION_TYPE_UNKNOWN:
892 default:
893 abort();
894 }
895 end:
896 return needs_tracer_notifier;
897 }
This page took 0.046596 seconds and 4 git commands to generate.