* 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
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, '\"')) {
*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));
if (connect(fd, (struct sockaddr *)&addrs, sizeof(addrs)) == -1) {
perror("\nClient connection error\n");
+ close(fd);
return -1;
}
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)
{
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;
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 */