#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
-#include <ust/lttng-ust-abi.h>
-#include <lttng-ust-comm.h>
-#include <ust/usterr-signal-safe.h>
#include <pthread.h>
#include <semaphore.h>
#include <time.h>
#include <assert.h>
#include <urcu/uatomic.h>
+#include <lttng-ust-comm.h>
+#include <ust/usterr-signal-safe.h>
+#include <ust/lttng-ust-abi.h>
+#include <ust/tracepoint.h>
+
+/*
+ * Has lttng ust comm constructor been called ?
+ */
+static int initialized;
+
/*
* communication thread mutex. Held when handling a command, also held
* by fork() to deal with removal of threads, and by exit path.
int socket;
pthread_t ust_listener; /* listener thread */
int root_handle;
+ int constructor_sem_posted;;
};
/* Socket from app (connect) to session daemon (listen) for communication */
.root_handle = -1,
};
+extern void ltt_ring_buffer_client_overwrite_init(void);
+extern void ltt_ring_buffer_client_discard_init(void);
+extern void ltt_ring_buffer_metadata_client_init(void);
+extern void ltt_ring_buffer_client_overwrite_exit(void);
+extern void ltt_ring_buffer_client_discard_exit(void);
+extern void ltt_ring_buffer_metadata_client_exit(void);
+
static
int setup_local_apps_socket(void)
{
}
static
-int handle_register_done(void)
+int handle_register_done(struct sock_info *sock_info)
{
int ret;
+ if (sock_info->constructor_sem_posted)
+ return 0;
+ sock_info->constructor_sem_posted = 1;
ret = uatomic_add_return(&sem_count, -1);
+ fprintf(stderr, "DEC ret %d\n", ret);
if (ret == 0) {
+ fprintf(stderr, "POST\n");
ret = sem_post(&constructor_wait);
assert(!ret);
}
switch (lum->cmd) {
case LTTNG_UST_REGISTER_DONE:
if (lum->handle == LTTNG_UST_ROOT_HANDLE)
- ret = handle_register_done();
+ ret = handle_register_done(sock_info);
else
ret = -EINVAL;
break;
* If we cannot find the sessiond daemon, don't delay
* constructor execution.
*/
- ret = handle_register_done();
+ ret = handle_register_done(sock_info);
assert(!ret);
pthread_mutex_unlock(<tng_ust_comm_mutex);
sleep(5);
* If we cannot register to the sessiond daemon, don't
* delay constructor execution.
*/
- ret = handle_register_done();
+ ret = handle_register_done(sock_info);
assert(!ret);
pthread_mutex_unlock(<tng_ust_comm_mutex);
sleep(5);
*/
/* TODO */
-void __attribute__((constructor)) lttng_ust_comm_init(void)
+void __attribute__((constructor)) lttng_ust_init(void)
{
struct timespec constructor_timeout;
int timeout_mode;
int ret;
+ if (uatomic_xchg(&initialized, 1) == 1)
+ return;
+
+ /*
+ * We want precise control over the order in which we construct
+ * our sub-libraries vs starting to receive commands from
+ * sessiond (otherwise leading to errors when trying to create
+ * sessiond before the init functions are completed).
+ */
init_usterr();
+ init_tracepoint();
+ ltt_ring_buffer_metadata_client_init();
+ ltt_ring_buffer_client_overwrite_init();
+ ltt_ring_buffer_client_discard_init();
timeout_mode = get_timeout(&constructor_timeout);
}
}
-void __attribute__((destructor)) lttng_ust_comm_exit(void)
+void __attribute__((destructor)) lttng_ust_exit(void)
{
int ret;
lttng_ust_abi_exit();
ltt_events_exit();
+ ltt_ring_buffer_client_discard_exit();
+ ltt_ring_buffer_client_overwrite_exit();
+ ltt_ring_buffer_metadata_client_exit();
+ exit_tracepoint();
}
#include <ust/kcompat/kcompat.h>
#include <urcu-bp.h>
#include <urcu/hlist.h>
+#include <urcu/uatomic.h>
#include <ust/usterr-signal-safe.h>
{
struct tracepoint_lib *pl, *iter;
+ init_tracepoint();
+
pl = (struct tracepoint_lib *) zmalloc(sizeof(struct tracepoint_lib));
pl->tracepoints_start = tracepoints_start;
return 0;
}
-void __attribute__((constructor)) init_tracepoint(void)
+void init_tracepoint(void)
{
+ if (uatomic_xchg(&initialized, 1) == 1)
+ return;
init_usterr();
- if (!initialized) {
- tracepoint_register_lib(__start___tracepoints_ptrs,
- __stop___tracepoints_ptrs
- - __start___tracepoints_ptrs);
- initialized = 1;
- }
+ tracepoint_register_lib(__start___tracepoints_ptrs,
+ __stop___tracepoints_ptrs
+ - __start___tracepoints_ptrs);
}
-void __attribute__((destructor)) destroy_tracepoint(void)
+void exit_tracepoint(void)
{
tracepoint_unregister_lib(__start___tracepoints_ptrs);
}