_hidden int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
const libxl_domain_config *guest_config);
-/* on failure, logs */
+/* `datalen` should be 1 byte
+ * When dealing with a non-blocking fd, it returns
+ * ERROR_NOT_READY on EWOULDBLOCK
+ * logs on other failures. */
int libxl__sendmsg_fds(libxl__gc *gc, int carrier,
const void *data, size_t datalen,
int nfds, const int fds[], const char *what);
struct iovec iov;
int r;
+ assert(datalen == 1);
+
iov.iov_base = (void*)data;
iov.iov_len = datalen;
msg.msg_controllen = cmsg->cmsg_len;
- r = sendmsg(carrier, &msg, 0);
- if (r < 0) {
- LOGE(ERROR, "failed to send fd-carrying message (%s)", what);
- return ERROR_FAIL;
- }
+ while (1) {
+ r = sendmsg(carrier, &msg, 0);
+ if (r < 0) {
+ if (errno == EINTR)
+ continue;
+ if (errno == EWOULDBLOCK) {
+ return ERROR_NOT_READY;
+ }
+ LOGE(ERROR, "failed to send fd-carrying message (%s)", what);
+ return ERROR_FAIL;
+ }
+ if (r != datalen) {
+ LOG(ERROR, "sendmsg have written %d instead of %zu",
+ r, datalen);
+ return ERROR_FAIL;
+ }
+ break;
+ };
return 0;
}