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.h>
9 #include <common/consumer/consumer.h>
10 #include <common/pipe.h>
11 #include <common/error.h>
14 #include <lttng/constant.h>
19 static char *pause_pipe_path
;
20 static struct lttng_pipe
*pause_pipe
;
21 static int *data_consumption_state
;
22 static enum lttng_consumer_type (*lttng_consumer_get_type
)(void);
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("unlink pause pipe");
40 free(pause_pipe_path
);
41 lttng_pipe_destroy(pause_pipe
);
45 * We use this testpoint, invoked at the start of the consumerd's data handling
46 * thread to create a named pipe/FIFO which a test application can use to either
47 * pause or resume the consumption of data.
49 int __testpoint_consumerd_thread_data(void);
50 int __testpoint_consumerd_thread_data(void)
53 const char *pause_pipe_path_prefix
, *domain
;
55 pause_pipe_path_prefix
= lttng_secure_getenv(
56 "CONSUMER_PAUSE_PIPE_PATH");
57 if (!pause_pipe_path_prefix
) {
63 * These symbols are exclusive to the consumerd process, hence we can't
64 * rely on their presence in the sessiond. Not looking-up these symbols
65 * dynamically would not allow this shared object to be LD_PRELOAD-ed
66 * when launching the session daemon.
68 data_consumption_state
= dlsym(NULL
, "data_consumption_paused");
69 LTTNG_ASSERT(data_consumption_state
);
70 lttng_consumer_get_type
= dlsym(NULL
, "lttng_consumer_get_type");
71 LTTNG_ASSERT(lttng_consumer_get_type
);
73 switch (lttng_consumer_get_type()) {
74 case LTTNG_CONSUMER_KERNEL
:
77 case LTTNG_CONSUMER32_UST
:
80 case LTTNG_CONSUMER64_UST
:
87 ret
= asprintf(&pause_pipe_path
, "%s-%s", pause_pipe_path_prefix
,
90 ERR("Failed to allocate pause pipe path");
94 DBG("Creating pause pipe at %s", pause_pipe_path
);
95 pause_pipe
= lttng_pipe_named_open(pause_pipe_path
,
96 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
98 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
103 /* Only the read end of the pipe is useful to us. */
104 ret
= lttng_pipe_write_close(pause_pipe
);
109 int __testpoint_consumerd_thread_data_poll(void);
110 int __testpoint_consumerd_thread_data_poll(void)
114 bool value_read
= false;
121 /* Purge pipe and only consider the freshest value. */
123 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
124 if (ret
== sizeof(value
)) {
127 } while (ret
== sizeof(value
));
129 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
132 *data_consumption_state
= !!value
;
133 DBG("Message received on pause pipe: %s data consumption",
134 *data_consumption_state
? "paused" : "resumed");
This page took 0.043307 seconds and 5 git commands to generate.