| 345 | } |
| 346 | |
| 347 | static int |
| 348 | create_unix_socket(struct vhost_user_socket *vsocket) |
| 349 | { |
| 350 | int fd; |
| 351 | struct sockaddr_un *un = &vsocket->un; |
| 352 | |
| 353 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
| 354 | if (fd < 0) |
| 355 | return -1; |
| 356 | VHOST_LOG_CONFIG(vsocket->path, INFO, "vhost-user %s: socket created, fd: %d\n", |
| 357 | vsocket->is_server ? "server" : "client", fd); |
| 358 | |
| 359 | if (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) { |
| 360 | VHOST_LOG_CONFIG(vsocket->path, ERR, |
| 361 | "vhost-user: can't set nonblocking mode for socket, fd: %d (%s)\n", |
| 362 | fd, strerror(errno)); |
| 363 | close(fd); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | memset(un, 0, sizeof(*un)); |
| 368 | un->sun_family = AF_UNIX; |
| 369 | strncpy(un->sun_path, vsocket->path, sizeof(un->sun_path)); |
| 370 | un->sun_path[sizeof(un->sun_path) - 1] = '\0'; |
| 371 | |
| 372 | vsocket->socket_fd = fd; |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int |
| 377 | vhost_user_start_server(struct vhost_user_socket *vsocket) |