2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <common/compat/getenv.hpp>
9 #include <common/consumer/consumer.hpp>
10 #include <common/error.hpp>
11 #include <common/pipe.hpp>
13 #include <lttng/constant.h>
14 #include <lttng/lttng-export.h>
22 static char *pause_pipe_path
;
23 static struct lttng_pipe
*pause_pipe
;
24 static int *data_consumption_state
;
25 using lttng_consumer_get_type_func
= enum lttng_consumer_type (*)();
26 static lttng_consumer_get_type_func lttng_consumer_get_type
;
28 int lttng_opt_verbose
;
32 static void __attribute__((destructor
)) pause_pipe_fini()
36 if (pause_pipe_path
) {
37 ret
= unlink(pause_pipe_path
);
39 PERROR("unlink pause pipe");
43 free(pause_pipe_path
);
44 lttng_pipe_destroy(pause_pipe
);
48 * We use this testpoint, invoked at the start of the consumerd's data handling
49 * thread to create a named pipe/FIFO which a test application can use to either
50 * pause or resume the consumption of data.
52 extern "C" LTTNG_EXPORT
int __testpoint_consumerd_thread_data(void);
53 int __testpoint_consumerd_thread_data(void)
56 const char *pause_pipe_path_prefix
, *domain
;
58 pause_pipe_path_prefix
= lttng_secure_getenv("CONSUMER_PAUSE_PIPE_PATH");
59 if (!pause_pipe_path_prefix
) {
65 * These symbols are exclusive to the consumerd process, hence we can't
66 * rely on their presence in the sessiond. Not looking-up these symbols
67 * dynamically would not allow this shared object to be LD_PRELOAD-ed
68 * when launching the session daemon.
70 data_consumption_state
= (int *) dlsym(nullptr, "data_consumption_paused");
71 LTTNG_ASSERT(data_consumption_state
);
72 lttng_consumer_get_type
=
73 (lttng_consumer_type(*)()) dlsym(nullptr, "lttng_consumer_get_type");
74 LTTNG_ASSERT(lttng_consumer_get_type
);
76 switch (lttng_consumer_get_type()) {
77 case LTTNG_CONSUMER_KERNEL
:
80 case LTTNG_CONSUMER32_UST
:
83 case LTTNG_CONSUMER64_UST
:
90 ret
= asprintf(&pause_pipe_path
, "%s-%s", pause_pipe_path_prefix
, domain
);
92 ERR("Failed to allocate pause pipe path");
96 DBG("Creating pause pipe at %s", pause_pipe_path
);
97 pause_pipe
= lttng_pipe_named_open(
98 pause_pipe_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
100 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
105 /* Only the read end of the pipe is useful to us. */
106 ret
= lttng_pipe_write_close(pause_pipe
);
111 extern "C" LTTNG_EXPORT
int __testpoint_consumerd_thread_data_poll(void);
112 int __testpoint_consumerd_thread_data_poll(void)
116 bool value_read
= false;
123 /* Purge pipe and only consider the freshest value. */
125 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
126 if (ret
== sizeof(value
)) {
129 } while (ret
== sizeof(value
));
131 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
134 *data_consumption_state
= !!value
;
135 DBG("Message received on pause pipe: %s data consumption",
136 *data_consumption_state
? "paused" : "resumed");