From: David Goulet Date: Thu, 8 Sep 2011 19:15:35 +0000 (-0400) Subject: Improve poll management of registration thread X-Git-Tag: v2.0-pre13~10 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=90014c57e763d8c3f10148800bfb8461a66fb987;p=lttng-tools.git Improve poll management of registration thread Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index d61cd7bc5..91f79b3c5 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -1141,59 +1141,66 @@ static void *thread_registration_apps(void *data) /* Thread quit pipe has been closed. Killing thread. */ if (pollfd[0].revents == POLLNVAL) { goto error; - } else if (pollfd[1].revents == POLLERR) { - ERR("Register apps socket poll error"); - goto error; } - sock = lttcomm_accept_unix_sock(apps_sock); - if (sock < 0) { + switch (pollfd[1].revents) { + case POLLNVAL: + case POLLHUP: + case POLLRDHUP: + case POLLERR: + ERR("Register apps socket poll error"); goto error; - } + case POLLIN: + sock = lttcomm_accept_unix_sock(apps_sock); + if (sock < 0) { + goto error; + } - /* Create UST registration command for enqueuing */ - ust_cmd = malloc(sizeof(struct ust_command)); - if (ust_cmd == NULL) { - perror("ust command malloc"); - goto error; - } + /* Create UST registration command for enqueuing */ + ust_cmd = malloc(sizeof(struct ust_command)); + if (ust_cmd == NULL) { + perror("ust command malloc"); + goto error; + } - /* - * Using message-based transmissions to ensure we don't have to deal - * with partially received messages. - */ - ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg, - sizeof(struct ust_register_msg)); - if (ret < 0 || ret < sizeof(struct ust_register_msg)) { - if (ret < 0) { - perror("lttcomm_recv_unix_sock register apps"); - } else { - ERR("Wrong size received on apps register"); + /* + * Using message-based transmissions to ensure we don't have to deal + * with partially received messages. + */ + ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg, + sizeof(struct ust_register_msg)); + if (ret < 0 || ret < sizeof(struct ust_register_msg)) { + if (ret < 0) { + perror("lttcomm_recv_unix_sock register apps"); + } else { + ERR("Wrong size received on apps register"); + } + free(ust_cmd); + close(sock); + continue; } - free(ust_cmd); - close(sock); - continue; - } - ust_cmd->sock = sock; + ust_cmd->sock = sock; - DBG("UST registration received with pid:%d ppid:%d uid:%d" - " gid:%d sock:%d name:%s (version %d.%d)", - ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid, - ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid, - ust_cmd->sock, ust_cmd->reg_msg.name, - ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor); - /* - * Lock free enqueue the registration request. - * The red pill has been taken! This apps will be part of the *system* - */ - cds_wfq_enqueue(&ust_cmd_queue.queue, &ust_cmd->node); + DBG("UST registration received with pid:%d ppid:%d uid:%d" + " gid:%d sock:%d name:%s (version %d.%d)", + ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid, + ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid, + ust_cmd->sock, ust_cmd->reg_msg.name, + ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor); + /* + * Lock free enqueue the registration request. + * The red pill has been taken! This apps will be part of the *system* + */ + cds_wfq_enqueue(&ust_cmd_queue.queue, &ust_cmd->node); - /* - * Wake the registration queue futex. - * Implicit memory barrier with the exchange in cds_wfq_enqueue. - */ - futex_nto1_wake(&ust_cmd_queue.futex); + /* + * Wake the registration queue futex. + * Implicit memory barrier with the exchange in cds_wfq_enqueue. + */ + futex_nto1_wake(&ust_cmd_queue.futex); + break; + } } error: