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