Fix: sessiond: trigger with condition not requiring event notifier cannot be listed
[lttng-tools.git] / src / bin / lttng-sessiond / trigger-error-query.c
1 /*
2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #include "event-notifier-error-accounting.h"
9 #include <lttng/error-query-internal.h>
10 #include <lttng/trigger/trigger-internal.h>
11 #include <lttng/action/action-internal.h>
12
13 LTTNG_HIDDEN
14 enum lttng_trigger_status lttng_trigger_add_error_results(
15 const struct lttng_trigger *trigger,
16 struct lttng_error_query_results *results)
17 {
18 enum lttng_trigger_status status;
19 uint64_t discarded_tracer_messages_count;
20 enum event_notifier_error_accounting_status error_accounting_status;
21 struct lttng_error_query_result *discarded_tracer_messages_counter = NULL;
22 const char *trigger_name;
23 uid_t trigger_owner;
24
25 status = lttng_trigger_get_name(trigger, &trigger_name);
26 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ?
27 trigger_name : "(unnamed)";
28 status = lttng_trigger_get_owner_uid(trigger,
29 &trigger_owner);
30 assert(status == LTTNG_TRIGGER_STATUS_OK);
31
32 /* Only add discarded tracer messages count for applicable triggers. */
33 if (!lttng_trigger_needs_tracer_notifier(trigger)) {
34 status = LTTNG_TRIGGER_STATUS_OK;
35 goto end;
36 }
37
38 error_accounting_status = event_notifier_error_accounting_get_count(
39 trigger, &discarded_tracer_messages_count);
40 if (error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
41 ERR("Failed to retrieve tracer discarded messages count for triger: triggger name = '%s', trigger owner uid = %d",
42 trigger_name, (int) trigger_owner);
43 status = LTTNG_TRIGGER_STATUS_ERROR;
44 goto end;
45 }
46
47 discarded_tracer_messages_counter = lttng_error_query_result_counter_create(
48 "discarded tracer messages",
49 "Count of messages discarded by the tracer due to a communication error with the session daemon",
50 discarded_tracer_messages_count);
51 if (!discarded_tracer_messages_counter) {
52 status = LTTNG_TRIGGER_STATUS_ERROR;
53 goto end;
54 }
55
56 if (lttng_error_query_results_add_result(
57 results, discarded_tracer_messages_counter)) {
58 status = LTTNG_TRIGGER_STATUS_ERROR;
59 goto end;
60 }
61
62 /* Ownership transferred to the results. */
63 discarded_tracer_messages_counter = NULL;
64
65 status = LTTNG_TRIGGER_STATUS_OK;
66 end:
67 lttng_error_query_result_destroy(discarded_tracer_messages_counter);
68 return status;
69 }
70
71 LTTNG_HIDDEN
72 enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
73 struct lttng_trigger *trigger,
74 struct lttng_error_query_results *results)
75 {
76 enum lttng_trigger_status status;
77 const char *trigger_name;
78 uid_t trigger_owner;
79 enum lttng_action_status action_status;
80
81 status = lttng_trigger_get_name(trigger, &trigger_name);
82 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ?
83 trigger_name : "(unnamed)";
84 status = lttng_trigger_get_owner_uid(trigger,
85 &trigger_owner);
86 assert(status == LTTNG_TRIGGER_STATUS_OK);
87
88 action_status = lttng_action_add_error_query_results(
89 lttng_trigger_get_action(trigger), results);
90 switch (action_status) {
91 case LTTNG_ACTION_STATUS_OK:
92 break;
93 default:
94 status = LTTNG_TRIGGER_STATUS_ERROR;
95 goto end;
96 }
97
98 status = LTTNG_TRIGGER_STATUS_OK;
99 end:
100 return status;
101 }
This page took 0.032394 seconds and 5 git commands to generate.