X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fpasswd%2Fnscd_query.c;h=d38e371bcda395855a4e9a125d4a75a115c76416;hb=55fb9a177316aa46c639d93dd0323d9a9a8c160c;hp=69a7815ecbf5b7a8d68a6f936a3126a1eb35a84f;hpb=4b5ca13fb170314e0e0c37b304ca56171625afd1;p=musl diff --git a/src/passwd/nscd_query.c b/src/passwd/nscd_query.c index 69a7815e..d38e371b 100644 --- a/src/passwd/nscd_query.c +++ b/src/passwd/nscd_query.c @@ -32,6 +32,7 @@ FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int * }, .msg_iovlen = 2 }; + int errno_save = errno; *swap = 0; retry: @@ -50,11 +51,14 @@ retry: return f; if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - /* If there isn't a running nscd we return -1 to indicate that - * that is precisely what happened - */ - if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) + /* If there isn't a running nscd we simulate a "not found" + * result and the caller is responsible for calling + * fclose on the (unconnected) socket. The value of + * errno must be left unchanged in this case. */ + if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) { + errno = errno_save; return f; + } goto error; }