X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Fchannel.c;h=5271aa13fbd76218fca47b8984c6a055fc84b35f;hb=3b33e9e731f2091e8aa13ea035c295ed6f101eac;hp=49a3684dbb1cbad3c6fb11ae5818238fdf806f0a;hpb=3647288fe42b25340f905046f3bd9aef21e12aaa;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/channel.c b/src/lib/lttng-ctl/channel.c index 49a3684db..5271aa13f 100644 --- a/src/lib/lttng-ctl/channel.c +++ b/src/lib/lttng-ctl/channel.c @@ -211,6 +211,7 @@ lttng_notification_channel_get_next_notification( struct lttng_notification *notification = NULL; enum lttng_notification_channel_status status = LTTNG_NOTIFICATION_CHANNEL_STATUS_OK; + fd_set read_fds; if (!channel || !_notification) { status = LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID; @@ -239,6 +240,28 @@ lttng_notification_channel_get_next_notification( goto end_unlock; } + /* + * Block on select() instead of the message reception itself as the + * recvmsg() wrappers always restard on EINTR. We choose to wait + * using select() in order to: + * 1) Return if a signal occurs, + * 2) Not deal with partially received messages. + * + * The drawback to this approach is that we assume that messages + * are complete/well formed. If a message is shorter than its + * announced length, receive_message() will block on recvmsg() + * and never return (even if a signal is received). + */ + FD_ZERO(&read_fds); + FD_SET(channel->socket, &read_fds); + ret = select(channel->socket + 1, &read_fds, NULL, NULL, NULL); + if (ret == -1) { + status = errno == EINTR ? + LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED : + LTTNG_NOTIFICATION_CHANNEL_STATUS_ERROR; + goto end_unlock; + } + ret = receive_message(channel); if (ret) { status = LTTNG_NOTIFICATION_CHANNEL_STATUS_ERROR; @@ -266,10 +289,8 @@ lttng_notification_channel_get_next_notification( end_unlock: pthread_mutex_unlock(&channel->lock); + *_notification = notification; end: - if (_notification) { - *_notification = notification; - } return status; } @@ -430,14 +451,14 @@ lttng_notification_channel_has_pending_notification( case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION: ret = enqueue_notification_from_current_message(channel); if (ret) { - goto end; + goto end_unlock; } *_notification_pending = true; break; case LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED: ret = enqueue_dropped_notification(channel); if (ret) { - goto end; + goto end_unlock; } *_notification_pending = true; break;