nwrap_files_cache_reload: avoid error on EBADF during stat
authorTJ Miller <millert@us.ibm.com>
Thu, 15 Oct 2020 19:07:17 +0000 (12:07 -0700)
committerAndreas Schneider <asn@samba.org>
Wed, 4 Nov 2020 15:35:54 +0000 (16:35 +0100)
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
src/nss_wrapper.c

index 4f4dc93bd0c568e3ebe6de7ec966574dc9741b8f..1630d49298cf30ea3db0e5a69d7c91b3a8e088ca 100644 (file)
@@ -2129,7 +2129,20 @@ reopen:
        }
 
        ret = fstat(nwrap->fd, &st);
-       if (ret != 0) {
+       if (ret != 0 && errno == EBADF && retried == false) {
+               /* maybe something closed the fd on our behalf */
+               NWRAP_LOG(NWRAP_LOG_TRACE,
+                         "fstat(%s) - %d:%s - reopen",
+                         nwrap->path,
+                         ret,
+                         strerror(errno));
+               retried = true;
+               memset(&nwrap->st, 0, sizeof(nwrap->st));
+               nwrap->fp = NULL;
+               nwrap->fd = -1;
+               goto reopen;
+       }
+       else if (ret != 0) {
                NWRAP_LOG(NWRAP_LOG_ERROR,
                          "fstat(%s) - %d:%s",
                          nwrap->path,