2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #include <common/compat/getenv.h>
19 #include <common/consumer/consumer.h>
20 #include <common/pipe.h>
21 #include <common/error.h>
24 #include <lttng/constant.h>
30 static char *pause_pipe_path
;
31 static struct lttng_pipe
*pause_pipe
;
32 static int *data_consumption_state
;
33 static enum lttng_consumer_type (*lttng_consumer_get_type
)(void);
35 int lttng_opt_verbose
;
40 void __attribute__((destructor
)) pause_pipe_fini(void)
44 if (pause_pipe_path
) {
45 ret
= unlink(pause_pipe_path
);
47 PERROR("unlink pause pipe");
51 free(pause_pipe_path
);
52 lttng_pipe_destroy(pause_pipe
);
56 * We use this testpoint, invoked at the start of the consumerd's data handling
57 * thread to create a named pipe/FIFO which a test application can use to either
58 * pause or resume the consumption of data.
60 int __testpoint_consumerd_thread_data(void)
63 const char *pause_pipe_path_prefix
, *domain
;
65 pause_pipe_path_prefix
= lttng_secure_getenv(
66 "CONSUMER_PAUSE_PIPE_PATH");
67 if (!pause_pipe_path_prefix
) {
73 * These symbols are exclusive to the consumerd process, hence we can't
74 * rely on their presence in the sessiond. Not looking-up these symbols
75 * dynamically would not allow this shared object to be LD_PRELOAD-ed
76 * when launching the session daemon.
78 data_consumption_state
= dlsym(NULL
, "data_consumption_paused");
79 assert(data_consumption_state
);
80 lttng_consumer_get_type
= dlsym(NULL
, "lttng_consumer_get_type");
81 assert(lttng_consumer_get_type
);
83 switch (lttng_consumer_get_type()) {
84 case LTTNG_CONSUMER_KERNEL
:
87 case LTTNG_CONSUMER32_UST
:
90 case LTTNG_CONSUMER64_UST
:
97 ret
= asprintf(&pause_pipe_path
, "%s-%s", pause_pipe_path_prefix
,
100 ERR("Failed to allocate pause pipe path");
104 DBG("Creating pause pipe at %s", pause_pipe_path
);
105 pause_pipe
= lttng_pipe_named_open(pause_pipe_path
,
106 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
, O_NONBLOCK
);
108 ERR("Failed to create pause pipe at %s", pause_pipe_path
);
113 /* Only the read end of the pipe is useful to us. */
114 ret
= lttng_pipe_write_close(pause_pipe
);
119 int __testpoint_consumerd_thread_data_poll(void)
123 bool value_read
= false;
130 /* Purge pipe and only consider the freshest value. */
132 ret
= lttng_pipe_read(pause_pipe
, &value
, sizeof(value
));
133 if (ret
== sizeof(value
)) {
136 } while (ret
== sizeof(value
));
138 ret
= (errno
== EAGAIN
) ? 0 : -errno
;
141 *data_consumption_state
= !!value
;
142 DBG("Message received on pause pipe: %s data consumption",
143 *data_consumption_state
? "paused" : "resumed");
This page took 0.033566 seconds and 5 git commands to generate.