event/dlb2: add dynamic logging
[dpdk.git] / lib / librte_telemetry / telemetry_legacy.c
index 72471cb..edd76ca 100644 (file)
@@ -2,10 +2,12 @@
  * Copyright(c) 2020 Intel Corporation
  */
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <pthread.h>
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
 /* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
 #undef RTE_USE_LIBBSD
@@ -77,15 +79,18 @@ static int
 register_client(const char *cmd __rte_unused, const char *params,
                char *buffer __rte_unused, int buf_len __rte_unused)
 {
+#ifndef RTE_EXEC_ENV_WINDOWS
        pthread_t th;
        char data[BUF_SIZE];
        int fd;
        struct sockaddr_un addrs;
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
        if (!strchr(params, ':')) {
                fprintf(stderr, "Invalid data\n");
                return -1;
        }
+#ifndef RTE_EXEC_ENV_WINDOWS
        strlcpy(data, strchr(params, ':'), sizeof(data));
        memcpy(data, &data[strlen(":\"")], strlen(data));
        if (!strchr(data, '\"')) {
@@ -95,6 +100,10 @@ register_client(const char *cmd __rte_unused, const char *params,
        *strchr(data, '\"') = 0;
 
        fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+       if (fd < 0) {
+               perror("Failed to open socket");
+               return -1;
+       }
        addrs.sun_family = AF_UNIX;
        strlcpy(addrs.sun_path, data, sizeof(addrs.sun_path));
 
@@ -105,9 +114,12 @@ register_client(const char *cmd __rte_unused, const char *params,
        }
        pthread_create(&th, NULL, &legacy_client_handler,
                        (void *)(uintptr_t)fd);
+#endif /* !RTE_EXEC_ENV_WINDOWS */
        return 0;
 }
 
+#ifndef RTE_EXEC_ENV_WINDOWS
+
 static int
 send_error_response(int s, int err)
 {
@@ -213,7 +225,7 @@ legacy_client_handler(void *sock_id)
        int ret;
        char buffer_recv[BUF_SIZE];
        /* receive data is not null terminated */
-       int bytes = read(s, buffer_recv, sizeof(buffer_recv));
+       int bytes = read(s, buffer_recv, sizeof(buffer_recv) - 1);
 
        while (bytes > 0) {
                buffer_recv[bytes] = 0;
@@ -230,8 +242,10 @@ legacy_client_handler(void *sock_id)
                        if (ret < 0)
                                printf("\nCould not send error response\n");
                }
-               bytes = read(s, buffer_recv, sizeof(buffer_recv));
+               bytes = read(s, buffer_recv, sizeof(buffer_recv) - 1);
        }
        close(s);
        return NULL;
 }
+
+#endif /* !RTE_EXEC_ENV_WINDOWS */