Fix: sessiond: rotation thread: fatal error when not finding a session
[lttng-tools.git] / src / bin / lttng-sessiond / trigger-error-query.cpp
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 enum lttng_trigger_status lttng_trigger_add_error_results(
14 const struct lttng_trigger *trigger,
15 struct lttng_error_query_results *results)
16 {
17 return LTTNG_TRIGGER_STATUS_OK;
18 }
19
20 enum lttng_trigger_status lttng_trigger_condition_add_error_results(
21 const struct lttng_trigger *trigger,
22 struct lttng_error_query_results *results)
23 {
24 enum lttng_trigger_status status;
25 uint64_t discarded_tracer_messages_count;
26 enum event_notifier_error_accounting_status error_accounting_status;
27 struct lttng_error_query_result *discarded_tracer_messages_counter = NULL;
28 const char *trigger_name;
29 uid_t trigger_owner;
30
31 status = lttng_trigger_get_name(trigger, &trigger_name);
32 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ?
33 trigger_name : "(anonymous)";
34 status = lttng_trigger_get_owner_uid(trigger,
35 &trigger_owner);
36 LTTNG_ASSERT(status == LTTNG_TRIGGER_STATUS_OK);
37
38 /*
39 * Only add discarded tracer messages count for applicable conditions.
40 * As of 2.13, only "event rule matches" conditions can generate
41 * reportable errors hence why this function is very specific to this
42 * condition type.
43 */
44 if (!lttng_trigger_needs_tracer_notifier(trigger)) {
45 status = LTTNG_TRIGGER_STATUS_OK;
46 goto end;
47 }
48
49 error_accounting_status = event_notifier_error_accounting_get_count(
50 trigger, &discarded_tracer_messages_count);
51 if (error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
52 ERR("Failed to retrieve tracer discarded messages count for trigger: trigger name = '%s', trigger owner uid = %d",
53 trigger_name, (int) trigger_owner);
54 status = LTTNG_TRIGGER_STATUS_ERROR;
55 goto end;
56 }
57
58 discarded_tracer_messages_counter = lttng_error_query_result_counter_create(
59 "discarded tracer messages",
60 "Count of messages discarded by the tracer due to a communication error with the session daemon",
61 discarded_tracer_messages_count);
62 if (!discarded_tracer_messages_counter) {
63 status = LTTNG_TRIGGER_STATUS_ERROR;
64 goto end;
65 }
66
67 if (lttng_error_query_results_add_result(
68 results, discarded_tracer_messages_counter)) {
69 status = LTTNG_TRIGGER_STATUS_ERROR;
70 goto end;
71 }
72
73 /* Ownership transferred to the results. */
74 discarded_tracer_messages_counter = NULL;
75
76 status = LTTNG_TRIGGER_STATUS_OK;
77 end:
78 lttng_error_query_result_destroy(discarded_tracer_messages_counter);
79 return status;
80 }
81
82 enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
83 struct lttng_trigger *trigger,
84 struct lttng_error_query_results *results)
85 {
86 enum lttng_trigger_status status;
87 const char *trigger_name;
88 uid_t trigger_owner;
89 enum lttng_action_status action_status;
90
91 status = lttng_trigger_get_name(trigger, &trigger_name);
92 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ?
93 trigger_name : "(anonymous)";
94 status = lttng_trigger_get_owner_uid(trigger,
95 &trigger_owner);
96 LTTNG_ASSERT(status == LTTNG_TRIGGER_STATUS_OK);
97
98 action_status = lttng_action_add_error_query_results(
99 lttng_trigger_get_action(trigger), results);
100 switch (action_status) {
101 case LTTNG_ACTION_STATUS_OK:
102 break;
103 default:
104 status = LTTNG_TRIGGER_STATUS_ERROR;
105 goto end;
106 }
107
108 status = LTTNG_TRIGGER_STATUS_OK;
109 end:
110 return status;
111 }
This page took 0.03284 seconds and 4 git commands to generate.