summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-07-31 15:57:50 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2015-07-31 15:57:50 +0200
commitb2fbba507f33db6e9be9282a182fc78f746287ae (patch)
tree99241ab0b3e743cac3201fb49d405d7772262063
parent560d56b50df09396e03a9f06e4abcd5388a31ae9 (diff)
downloadnq-b2fbba507f33db6e9be9282a182fc78f746287ae.tar.gz
nq-b2fbba507f33db6e9be9282a182fc78f746287ae.tar.xz
nq-b2fbba507f33db6e9be9282a182fc78f746287ae.zip
tweaks
-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);
 		}
 	}