servers: accept lstat() failing due to the file missing

In `bind_unix_socket()`, before retrying `bind()`.

Before this patch the code wanted to check if the to-be-deleted unix
socket path was indeed a socket, before deleting it and retrying to
bind. If `lstat()` failed for any reason, it skipped retry. Fix to retry
if `lstat()` failed because of the file missing.

Ref: https://pubs.opengroup.org/onlinepubs/9799919799/functions/lstat.html

Follow-up to 0882e3951d #22026
Follow-up to 03bc93bd32 #22021
Follow-up to e70f8ebd34 #22020
Follow-up to 30e491e5c9 #7034
Follow-up to 99fb36797a

Closes #22010
This commit is contained in:
Viktor Szakats 2026-06-15 11:18:14 +02:00
parent eb6d1e098e
commit 0dae3b2690
No known key found for this signature in database

View file

@ -699,12 +699,13 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
/* socket server is not alive, now check if it was actually a socket. */
{
curlx_struct_stat statbuf;
if(lstat(unix_socket, &statbuf)) {
rc = lstat(unix_socket, &statbuf);
if(rc && errno != ENOENT) {
logmsg("Error binding socket, failed to stat %s (%d) %s", unix_socket,
errno, curlx_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
if((statbuf.st_mode & S_IFMT) != S_IFSOCK) {
if(!rc && (statbuf.st_mode & S_IFMT) != S_IFSOCK) {
logmsg("Error binding socket, %s is not a socket", unix_socket);
return -1;
}