fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / tests / regression / tools / notification / sessiond_testpoints.cpp
CommitLineData
38eb8a68
FD
1/*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
c9e313bc
SM
9#include <common/compat/getenv.hpp>
10#include <common/consumer/consumer.hpp>
c9e313bc 11#include <common/error.hpp>
28ab034a
JG
12#include <common/pipe.hpp>
13
38eb8a68 14#include <lttng/constant.h>
4bd69c5f 15#include <lttng/lttng-export.h>
28ab034a 16
38eb8a68 17#include <dlfcn.h>
28ab034a
JG
18#include <fcntl.h>
19#include <stdbool.h>
38eb8a68 20#include <stdio.h>
28ab034a 21#include <unistd.h>
38eb8a68
FD
22
23static char *pause_pipe_path;
24static struct lttng_pipe *pause_pipe;
28ab034a
JG
25static int *notifier_notif_consumption_state;
26;
38eb8a68
FD
27
28int lttng_opt_verbose;
29int lttng_opt_mi;
30int lttng_opt_quiet;
31
cd9adb8b 32static void __attribute__((destructor)) pause_pipe_fini()
38eb8a68
FD
33{
34 int ret;
35
36 if (pause_pipe_path) {
37 ret = unlink(pause_pipe_path);
38 if (ret) {
28ab034a 39 PERROR("Failed to unlink pause pipe: path = %s", pause_pipe_path);
38eb8a68
FD
40 }
41 }
42
43 free(pause_pipe_path);
44 lttng_pipe_destroy(pause_pipe);
45}
46
97535efa 47extern "C" LTTNG_EXPORT int __testpoint_sessiond_thread_notification(void);
38eb8a68
FD
48int __testpoint_sessiond_thread_notification(void)
49{
50 int ret = 0;
51 const char *pause_pipe_path_prefix;
52
28ab034a 53 pause_pipe_path_prefix = lttng_secure_getenv("NOTIFIER_PAUSE_PIPE_PATH");
38eb8a68
FD
54 if (!pause_pipe_path_prefix) {
55 ret = -1;
56 goto end;
57 }
58
cd9adb8b 59 notifier_notif_consumption_state = (int *) dlsym(nullptr, "notifier_consumption_paused");
a0377dfe 60 LTTNG_ASSERT(notifier_notif_consumption_state);
38eb8a68
FD
61
62 ret = asprintf(&pause_pipe_path, "%s", pause_pipe_path_prefix);
63 if (ret < 1) {
64 ERR("Failed to allocate pause pipe path");
65 goto end;
66 }
67
68 DBG("Creating pause pipe at %s", pause_pipe_path);
28ab034a
JG
69 pause_pipe = lttng_pipe_named_open(
70 pause_pipe_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, O_NONBLOCK);
38eb8a68
FD
71 if (!pause_pipe) {
72 ERR("Failed to create pause pipe at %s", pause_pipe_path);
73 ret = -1;
74 goto end;
75 }
76
77 /* Only the read end of the pipe is useful to us. */
78 ret = lttng_pipe_write_close(pause_pipe);
79end:
80 return ret;
81}
82
97535efa 83extern "C" LTTNG_EXPORT int __testpoint_sessiond_handle_notifier_event_pipe(void);
38eb8a68
FD
84int __testpoint_sessiond_handle_notifier_event_pipe(void)
85{
86 int ret = 0;
87 uint8_t value;
88 bool value_read = false;
89
90 if (!pause_pipe) {
91 ret = -1;
92 goto end;
93 }
94
95 /* Purge pipe and only consider the freshest value. */
96 do {
97 ret = lttng_pipe_read(pause_pipe, &value, sizeof(value));
98 if (ret == sizeof(value)) {
99 value_read = true;
100 }
101 } while (ret == sizeof(value));
102
103 ret = (errno == EAGAIN) ? 0 : -errno;
104
105 if (value_read) {
106 *notifier_notif_consumption_state = !!value;
107 DBG("Message received on pause pipe: %s data consumption",
28ab034a 108 *notifier_notif_consumption_state ? "paused" : "resumed");
38eb8a68
FD
109 }
110end:
111 return ret;
112}
This page took 0.047065 seconds and 4 git commands to generate.