Skip to content

Commit

Permalink
tests: fix error handling around UNIX sockets
Browse files Browse the repository at this point in the history
The wrong error code was checked on Windows, which may have caused all
UNIX sockets to be reported as error and the tests skipped.

Fixes #11258
Closes #11265
  • Loading branch information
dfandrich committed Jun 7, 2023
1 parent 3f8fc25 commit 818d6c1
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/server/util.c
Expand Up @@ -819,23 +819,21 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
sau->sun_family = AF_UNIX;
strncpy(sau->sun_path, unix_socket, sizeof(sau->sun_path) - 1);
rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
if(0 != rc && errno == EADDRINUSE) {
if(0 != rc && SOCKERRNO == EADDRINUSE) {
struct_stat statbuf;
/* socket already exists. Perhaps it is stale? */
curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0);
if(CURL_SOCKET_BAD == unixfd) {
error = SOCKERRNO;
logmsg("Error binding socket, failed to create socket at %s: (%d) %s",
unix_socket, error, strerror(error));
logmsg("Failed to create socket at %s: (%d)", unix_socket, SOCKERRNO);
perror("Error creating socket");
return rc;
}
/* check whether the server is alive */
rc = connect(unixfd, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
error = errno;
error = SOCKERRNO;
sclose(unixfd);
if(ECONNREFUSED != error) {
logmsg("Error binding socket, failed to connect to %s: (%d) %s",
unix_socket, error, strerror(error));
logmsg("Failed to connect to %s: (%d)", unix_socket, error);
return rc;
}
/* socket server is not alive, now check if it was actually a socket. */
Expand All @@ -852,8 +850,8 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
}
#ifdef S_IFSOCK
if((statbuf.st_mode & S_IFSOCK) != S_IFSOCK) {
logmsg("Error binding socket, failed to stat %s: (%d) %s",
unix_socket, error, strerror(error));
logmsg("Error binding socket, failed to stat %s: (%d)",
unix_socket, errno);
return rc;
}
#endif
Expand Down

0 comments on commit 818d6c1

Please sign in to comment.