| 470 | } |
| 471 | |
| 472 | static int |
| 473 | create_socket(char *path) |
| 474 | { |
| 475 | int sock = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
| 476 | if (sock < 0) { |
| 477 | TMTY_LOG(ERR, "Error with socket creation, %s\n", strerror(errno)); |
| 478 | return -1; |
| 479 | } |
| 480 | |
| 481 | struct sockaddr_un sun = {.sun_family = AF_UNIX}; |
| 482 | strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); |
| 483 | TMTY_LOG(DEBUG, "Attempting socket bind to path '%s'\n", path); |
| 484 | |
| 485 | if (bind(sock, (void *) &sun, sizeof(sun)) < 0) { |
| 486 | struct stat st; |
| 487 | |
| 488 | TMTY_LOG(DEBUG, "Initial bind to socket '%s' failed.\n", path); |
| 489 | |
| 490 | /* first check if we have a runtime dir */ |
| 491 | if (stat(socket_dir, &st) < 0 || !S_ISDIR(st.st_mode)) { |
| 492 | TMTY_LOG(ERR, "Cannot access DPDK runtime directory: %s\n", socket_dir); |
| 493 | close(sock); |
| 494 | return -ENOENT; |
| 495 | } |
| 496 | |
| 497 | /* check if current socket is active */ |
| 498 | if (connect(sock, (void *)&sun, sizeof(sun)) == 0) { |
| 499 | close(sock); |
| 500 | return -EADDRINUSE; |
| 501 | } |
| 502 | |
| 503 | /* socket is not active, delete and attempt rebind */ |
| 504 | TMTY_LOG(DEBUG, "Attempting unlink and retrying bind\n"); |
| 505 | unlink(sun.sun_path); |
| 506 | if (bind(sock, (void *) &sun, sizeof(sun)) < 0) { |
| 507 | TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno)); |
| 508 | close(sock); |
| 509 | return -errno; /* if unlink failed, this will be -EADDRINUSE as above */ |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | if (listen(sock, 1) < 0) { |
| 514 | TMTY_LOG(ERR, "Error calling listen for socket: %s\n", strerror(errno)); |
| 515 | unlink(sun.sun_path); |
| 516 | close(sock); |
| 517 | return -errno; |
| 518 | } |
| 519 | TMTY_LOG(DEBUG, "Socket creation and binding ok\n"); |
| 520 | |
| 521 | return sock; |
| 522 | } |
| 523 | |
| 524 | static void |
| 525 | set_thread_name(pthread_t id __rte_unused, const char *name __rte_unused) |