| 573 | } |
| 574 | |
| 575 | static int |
| 576 | telemetry_v2_init(void) |
| 577 | { |
| 578 | char spath[sizeof(v2_socket.path)]; |
| 579 | pthread_t t_new; |
| 580 | short suffix = 0; |
| 581 | int rc; |
| 582 | |
| 583 | v2_socket.num_clients = &v2_clients; |
| 584 | rte_telemetry_register_cmd("/", list_commands, |
| 585 | "Returns list of available commands, Takes no parameters"); |
| 586 | rte_telemetry_register_cmd("/info", json_info, |
| 587 | "Returns DPDK Telemetry information. Takes no parameters"); |
| 588 | rte_telemetry_register_cmd("/help", command_help, |
| 589 | "Returns help text for a command. Parameters: string command"); |
| 590 | v2_socket.fn = client_handler; |
| 591 | if (strlcpy(spath, get_socket_path(socket_dir, 2), sizeof(spath)) >= sizeof(spath)) { |
| 592 | TMTY_LOG(ERR, "Error with socket binding, path too long\n"); |
| 593 | return -1; |
| 594 | } |
| 595 | memcpy(v2_socket.path, spath, sizeof(v2_socket.path)); |
| 596 | |
| 597 | v2_socket.sock = create_socket(v2_socket.path); |
| 598 | while (v2_socket.sock < 0) { |
| 599 | /* bail out on unexpected error, or suffix wrap-around */ |
| 600 | if (v2_socket.sock != -EADDRINUSE || suffix < 0) { |
| 601 | v2_socket.path[0] = '\0'; /* clear socket path */ |
| 602 | return -1; |
| 603 | } |
| 604 | /* add a suffix to the path if the basic version fails */ |
| 605 | if (snprintf(v2_socket.path, sizeof(v2_socket.path), "%s:%d", |
| 606 | spath, ++suffix) >= (int)sizeof(v2_socket.path)) { |
| 607 | TMTY_LOG(ERR, "Error with socket binding, path too long\n"); |
| 608 | return -1; |
| 609 | } |
| 610 | v2_socket.sock = create_socket(v2_socket.path); |
| 611 | } |
| 612 | rc = pthread_create(&t_new, NULL, socket_listener, &v2_socket); |
| 613 | if (rc != 0) { |
| 614 | TMTY_LOG(ERR, "Error with create socket thread: %s\n", |
| 615 | strerror(rc)); |
| 616 | close(v2_socket.sock); |
| 617 | v2_socket.sock = -1; |
| 618 | unlink(v2_socket.path); |
| 619 | v2_socket.path[0] = '\0'; |
| 620 | return -1; |
| 621 | } |
| 622 | pthread_setaffinity_np(t_new, sizeof(*thread_cpuset), thread_cpuset); |
| 623 | set_thread_name(t_new, "dpdk-telemet-v2"); |
| 624 | pthread_detach(t_new); |
| 625 | atexit(unlink_sockets); |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | #endif /* !RTE_EXEC_ENV_WINDOWS */ |
| 631 |
no test coverage detected