about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nq.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/nq.c b/nq.c
index 5117287..83909c8 100644
--- a/nq.c
+++ b/nq.c
@@ -183,19 +183,23 @@ again:
 	while ((ent = readdir(dir))) {
 		if (ent->d_name[0] == ',' &&
 		    strcmp(ent->d_name, lockfile+1) < 0) {
-			int f = openat(dirfd, ent->d_name, O_RDWR);
+			int fd;
+
+			fd = openat(dirfd, ent->d_name, O_RDWR);
+			if (fd < 0)
+				continue;
     
-			if (flock(f, LOCK_EX | LOCK_NB) == -1 &&
+			if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
 			    errno == EWOULDBLOCK) {
-				flock(f, LOCK_EX);   /* sit it out.  */
+				flock(fd, LOCK_EX);   /* sit it out.  */
 
-				close(f);
+				close(fd);
 				rewinddir(dir);
 				goto again;
 			}
     
-			fchmod(f, 0600);
-			close(f);
+			fchmod(fd, 0600);
+			close(fd);
 		}
 	}