| 526 | } |
| 527 | |
| 528 | static int |
| 529 | vhost_user_start_client(struct vhost_user_socket *vsocket) |
| 530 | { |
| 531 | int ret; |
| 532 | int fd = vsocket->socket_fd; |
| 533 | const char *path = vsocket->path; |
| 534 | struct vhost_user_reconnect *reconn; |
| 535 | |
| 536 | ret = vhost_user_connect_nonblock(vsocket->path, fd, (struct sockaddr *)&vsocket->un, |
| 537 | sizeof(vsocket->un)); |
| 538 | if (ret == 0) { |
| 539 | vhost_user_add_connection(fd, vsocket); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | VHOST_LOG_CONFIG(path, WARNING, "failed to connect: %s\n", strerror(errno)); |
| 544 | |
| 545 | if (ret == -2 || !vsocket->reconnect) { |
| 546 | close(fd); |
| 547 | return -1; |
| 548 | } |
| 549 | |
| 550 | VHOST_LOG_CONFIG(path, INFO, "reconnecting...\n"); |
| 551 | reconn = malloc(sizeof(*reconn)); |
| 552 | if (reconn == NULL) { |
| 553 | VHOST_LOG_CONFIG(path, ERR, "failed to allocate memory for reconnect\n"); |
| 554 | close(fd); |
| 555 | return -1; |
| 556 | } |
| 557 | reconn->un = vsocket->un; |
| 558 | reconn->fd = fd; |
| 559 | reconn->vsocket = vsocket; |
| 560 | pthread_mutex_lock(&reconn_list.mutex); |
| 561 | TAILQ_INSERT_TAIL(&reconn_list.head, reconn, next); |
| 562 | pthread_mutex_unlock(&reconn_list.mutex); |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static struct vhost_user_socket * |
| 568 | find_vhost_user_socket(const char *path) |
no test coverage detected