X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ust-comm.c;h=88ac59655d7208f434c9e255b702a32b31758213;hb=2eda209b5805e2ece837f436fca063ba2775e4ff;hp=36f57efb25f4d97c31bcb04b7fd207f2807b9a8c;hpb=03c261a4a68e20cdcc68dc96531225c75a289235;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 36f57efb..88ac5965 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -46,6 +46,7 @@ #include "tracepoint-internal.h" #include "ltt-tracer-core.h" #include "compat.h" +#include "../libringbuffer/tlsfixup.h" /* * Has lttng ust comm constructor been called ? @@ -235,6 +236,7 @@ int handle_message(struct sock_info *sock_info, struct ustcomm_ust_reply lur; int shm_fd, wait_fd; union ust_args args; + ssize_t len; ust_lock(); @@ -319,14 +321,20 @@ end: || lum->cmd == LTTNG_UST_CHANNEL || lum->cmd == LTTNG_UST_METADATA) && lur.ret_code == USTCOMM_OK) { + int sendret = 0; + /* we also need to send the file descriptors. */ ret = ustcomm_send_fds_unix_sock(sock, &shm_fd, &shm_fd, 1, sizeof(int)); if (ret < 0) { perror("send shm_fd"); - goto error; + sendret = ret; } + /* + * The sessiond expects 2 file descriptors, even upon + * error. + */ ret = ustcomm_send_fds_unix_sock(sock, &wait_fd, &wait_fd, 1, sizeof(int)); @@ -334,6 +342,26 @@ end: perror("send wait_fd"); goto error; } + if (sendret) { + ret = sendret; + goto error; + } + } + /* + * LTTNG_UST_TRACEPOINT_FIELD_LIST_GET needs to send the field + * after the reply. + */ + if (lur.ret_code == USTCOMM_OK) { + switch (lum->cmd) { + case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET: + len = ustcomm_send_unix_sock(sock, + &args.field_list.entry, + sizeof(args.field_list.entry)); + if (len != sizeof(args.field_list.entry)) { + ret = -1; + goto error; + } + } } /* * We still have the memory map reference, and the fds have been @@ -390,7 +418,7 @@ void cleanup_sock_info(struct sock_info *sock_info, int exiting) int ret; if (sock_info->socket != -1) { - ret = close(sock_info->socket); + ret = ustcomm_close_unix_sock(sock_info->socket); if (ret) { ERR("Error closing apps socket"); } @@ -670,7 +698,7 @@ restart: } if (sock_info->socket != -1) { - ret = close(sock_info->socket); + ret = ustcomm_close_unix_sock(sock_info->socket); if (ret) { ERR("Error closing %s apps socket", sock_info->name); } @@ -821,12 +849,22 @@ int get_timeout(struct timespec *constructor_timeout) void __attribute__((constructor)) lttng_ust_init(void) { struct timespec constructor_timeout; + sigset_t sig_all_blocked, orig_parent_mask; int timeout_mode; int ret; if (uatomic_xchg(&initialized, 1) == 1) return; + /* + * Fixup interdependency between TLS fixup mutex (which happens + * to be the dynamic linker mutex) and ust_lock, taken within + * the ust lock. + */ + lttng_fixup_event_tls(); + lttng_fixup_ringbuffer_tls(); + lttng_fixup_vtid_tls(); + /* * We want precise control over the order in which we construct * our sub-libraries vs starting to receive commands from @@ -848,6 +886,18 @@ void __attribute__((constructor)) lttng_ust_init(void) if (ret) { ERR("Error setting up to local apps"); } + + /* A new thread created by pthread_create inherits the signal mask + * from the parent. To avoid any signal being received by the + * listener thread, we block all signals temporarily in the parent, + * while we create the listener thread. + */ + sigfillset(&sig_all_blocked); + ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_parent_mask); + if (ret) { + PERROR("pthread_sigmask: %s", strerror(ret)); + } + ret = pthread_create(&local_apps.ust_listener, NULL, ust_listener_thread, &local_apps); @@ -858,6 +908,12 @@ void __attribute__((constructor)) lttng_ust_init(void) handle_register_done(&local_apps); } + /* Restore original signal mask in parent */ + ret = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL); + if (ret) { + PERROR("pthread_sigmask: %s", strerror(ret)); + } + switch (timeout_mode) { case 1: /* timeout wait */ do {