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>
20 static char *pause_pipe_path
;
21 static struct lttng_pipe
*pause_pipe
;
22 static int *notifier_notif_consumption_state
;;
24 int lttng_opt_verbose
;
29 void __attribute__((destructor
)) pause_pipe_fini(void)
33 if (pause_pipe_path
) {
34 ret
= unlink(pause_pipe_path
);
36 PERROR("Failed to unlink pause pipe: path = %s",
41 free(pause_pipe_path
);
42 lttng_pipe_destroy(pause_pipe
);
45 int __testpoint_sessiond_thread_notification(void);
46 int __testpoint_sessiond_thread_notification(void)
49 const char *pause_pipe_path_prefix
;
51 pause_pipe_path_prefix
= lttng_secure_getenv(
52 "NOTIFIER_PAUSE_PIPE_PATH");
53 if (!pause_pipe_path_prefix
) {
58 notifier_notif_consumption_state
= dlsym(NULL
, "notifier_consumption_paused");
59 LTTNG_ASSERT(notifier_notif_consumption_state
);
61 ret
= asprintf(&pause_pipe_path
, "%s", pause_pipe_path_prefix
);
63 ERR("Failed to allocate pause pipe path");
67 DBG("Creating pause pipe at %s", pause_pipe_path
);
68 pause_pipe
= lttng_pipe_named_open(pause_pipe_path
,
69 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
71 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
76 /* Only the read end of the pipe is useful to us. */
77 ret
= lttng_pipe_write_close(pause_pipe
);
82 int __testpoint_sessiond_handle_notifier_event_pipe(void);
83 int __testpoint_sessiond_handle_notifier_event_pipe(void)
87 bool value_read
= false;
94 /* Purge pipe and only consider the freshest value. */
96 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
97 if (ret
== sizeof(value
)) {
100 } while (ret
== sizeof(value
));
102 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
105 *notifier_notif_consumption_state
= !!value
;
106 DBG("Message received on pause pipe: %s data consumption",
107 *notifier_notif_consumption_state
? "paused" : "resumed");