2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #include <common/compat/getenv.hpp>
10 #include <common/consumer/consumer.hpp>
11 #include <common/pipe.hpp>
12 #include <common/error.hpp>
15 #include <lttng/constant.h>
16 #include <lttng/lttng-export.h>
21 static char *pause_pipe_path
;
22 static struct lttng_pipe
*pause_pipe
;
23 static int *notifier_notif_consumption_state
;;
25 int lttng_opt_verbose
;
30 void __attribute__((destructor
)) pause_pipe_fini(void)
34 if (pause_pipe_path
) {
35 ret
= unlink(pause_pipe_path
);
37 PERROR("Failed to unlink pause pipe: path = %s",
42 free(pause_pipe_path
);
43 lttng_pipe_destroy(pause_pipe
);
46 extern "C" LTTNG_EXPORT
int __testpoint_sessiond_thread_notification(void);
47 int __testpoint_sessiond_thread_notification(void)
50 const char *pause_pipe_path_prefix
;
52 pause_pipe_path_prefix
= lttng_secure_getenv(
53 "NOTIFIER_PAUSE_PIPE_PATH");
54 if (!pause_pipe_path_prefix
) {
59 notifier_notif_consumption_state
= (int *) dlsym(NULL
, "notifier_consumption_paused");
60 LTTNG_ASSERT(notifier_notif_consumption_state
);
62 ret
= asprintf(&pause_pipe_path
, "%s", pause_pipe_path_prefix
);
64 ERR("Failed to allocate pause pipe path");
68 DBG("Creating pause pipe at %s", pause_pipe_path
);
69 pause_pipe
= lttng_pipe_named_open(pause_pipe_path
,
70 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
72 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
77 /* Only the read end of the pipe is useful to us. */
78 ret
= lttng_pipe_write_close(pause_pipe
);
83 extern "C" LTTNG_EXPORT
int __testpoint_sessiond_handle_notifier_event_pipe(void);
84 int __testpoint_sessiond_handle_notifier_event_pipe(void)
88 bool value_read
= false;
95 /* Purge pipe and only consider the freshest value. */
97 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
98 if (ret
== sizeof(value
)) {
101 } while (ret
== sizeof(value
));
103 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
106 *notifier_notif_consumption_state
= !!value
;
107 DBG("Message received on pause pipe: %s data consumption",
108 *notifier_notif_consumption_state
? "paused" : "resumed");