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.h>
10 #include <common/consumer/consumer.h>
11 #include <common/pipe.h>
12 #include <common/error.h>
15 #include <lttng/constant.h>
21 static char *pause_pipe_path
;
22 static struct lttng_pipe
*pause_pipe
;
23 static int *trigger_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("unlink pause pipe");
41 free(pause_pipe_path
);
42 lttng_pipe_destroy(pause_pipe
);
47 int __testpoint_sessiond_thread_notification(void);
48 int __testpoint_sessiond_thread_notification(void)
51 const char *pause_pipe_path_prefix
;
53 pause_pipe_path_prefix
= lttng_secure_getenv(
54 "TRIGGER_PAUSE_PIPE_PATH");
55 if (!pause_pipe_path_prefix
) {
60 trigger_notif_consumption_state
= dlsym(NULL
, "trigger_consumption_paused");
61 assert(trigger_notif_consumption_state
);
63 ret
= asprintf(&pause_pipe_path
, "%s", pause_pipe_path_prefix
);
65 ERR("Failed to allocate pause pipe path");
69 DBG("Creating pause pipe at %s", pause_pipe_path
);
70 pause_pipe
= lttng_pipe_named_open(pause_pipe_path
,
71 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
73 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
78 /* Only the read end of the pipe is useful to us. */
79 ret
= lttng_pipe_write_close(pause_pipe
);
84 int __testpoint_sessiond_handle_trigger_event_pipe(void);
85 int __testpoint_sessiond_handle_trigger_event_pipe(void)
89 bool value_read
= false;
96 /* Purge pipe and only consider the freshest value. */
98 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
99 if (ret
== sizeof(value
)) {
102 } while (ret
== sizeof(value
));
104 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
107 *trigger_notif_consumption_state
= !!value
;
108 DBG("Message received on pause pipe: %s data consumption",
109 *trigger_notif_consumption_state
? "paused" : "resumed");