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