| 374 | } |
| 375 | |
| 376 | static int |
| 377 | vhost_user_start_server(struct vhost_user_socket *vsocket) |
| 378 | { |
| 379 | int ret; |
| 380 | int fd = vsocket->socket_fd; |
| 381 | const char *path = vsocket->path; |
| 382 | |
| 383 | /* |
| 384 | * bind () may fail if the socket file with the same name already |
| 385 | * exists. But the library obviously should not delete the file |
| 386 | * provided by the user, since we can not be sure that it is not |
| 387 | * being used by other applications. Moreover, many applications form |
| 388 | * socket names based on user input, which is prone to errors. |
| 389 | * |
| 390 | * The user must ensure that the socket does not exist before |
| 391 | * registering the vhost driver in server mode. |
| 392 | */ |
| 393 | ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un)); |
| 394 | if (ret < 0) { |
| 395 | VHOST_LOG_CONFIG(path, ERR, "failed to bind: %s; remove it and try again\n", |
| 396 | strerror(errno)); |
| 397 | goto err; |
| 398 | } |
| 399 | VHOST_LOG_CONFIG(path, INFO, "binding succeeded\n"); |
| 400 | |
| 401 | ret = listen(fd, MAX_VIRTIO_BACKLOG); |
| 402 | if (ret < 0) |
| 403 | goto err; |
| 404 | |
| 405 | ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection, |
| 406 | NULL, vsocket); |
| 407 | if (ret < 0) { |
| 408 | VHOST_LOG_CONFIG(path, ERR, "failed to add listen fd %d to vhost server fdset\n", |
| 409 | fd); |
| 410 | goto err; |
| 411 | } |
| 412 | |
| 413 | return 0; |
| 414 | |
| 415 | err: |
| 416 | close(fd); |
| 417 | return -1; |
| 418 | } |
| 419 | |
| 420 | struct vhost_user_reconnect { |
| 421 | struct sockaddr_un un; |
no test coverage detected