sessiond: implement EXECUTE_ERROR_QUERY command
[deliverable/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 error_accounting_status = event_notifier_error_accounting_get_count(
33 trigger, &discarded_tracer_messages_count);
34 if (error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
35 ERR("Failed to retrieve tracer discarded messages count for triger: triggger name = '%s', trigger owner uid = %d",
36 trigger_name, (int) trigger_owner);
37 status = LTTNG_TRIGGER_STATUS_ERROR;
38 goto end;
39 }
40
41 discarded_tracer_messages_counter = lttng_error_query_result_counter_create(
42 "discarded tracer messages",
43 "Count of messages discarded by the tracer due to a communication error with the session daemon",
44 discarded_tracer_messages_count);
45 if (!discarded_tracer_messages_counter) {
46 status = LTTNG_TRIGGER_STATUS_ERROR;
47 goto end;
48 }
49
50 if (lttng_error_query_results_add_result(
51 results, discarded_tracer_messages_counter)) {
52 status = LTTNG_TRIGGER_STATUS_ERROR;
53 goto end;
54 }
55
56 /* Ownership transferred to the results. */
57 discarded_tracer_messages_counter = NULL;
58
59 status = LTTNG_TRIGGER_STATUS_OK;
60 end:
61 lttng_error_query_result_destroy(discarded_tracer_messages_counter);
62 return status;
63 }
64
65 LTTNG_HIDDEN
66 enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
67 struct lttng_trigger *trigger,
68 struct lttng_error_query_results *results)
69 {
70 enum lttng_trigger_status status;
71 const char *trigger_name;
72 uid_t trigger_owner;
73 enum lttng_action_status action_status;
74
75 status = lttng_trigger_get_name(trigger, &trigger_name);
76 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ?
77 trigger_name : "(unnamed)";
78 status = lttng_trigger_get_owner_uid(trigger,
79 &trigger_owner);
80 assert(status == LTTNG_TRIGGER_STATUS_OK);
81
82 action_status = lttng_action_add_error_query_results(
83 lttng_trigger_get_action(trigger), results);
84 switch (action_status) {
85 case LTTNG_ACTION_STATUS_OK:
86 status = LTTNG_TRIGGER_STATUS_OK;
87 goto end;
88 default:
89 status = LTTNG_TRIGGER_STATUS_ERROR;
90 goto end;
91 }
92
93 status = LTTNG_TRIGGER_STATUS_OK;
94 end:
95 return status;
96 }
This page took 0.035748 seconds and 6 git commands to generate.