diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-07-31 15:57:50 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-07-31 15:57:50 +0200 |
commit | b2fbba507f33db6e9be9282a182fc78f746287ae (patch) | |
tree | 99241ab0b3e743cac3201fb49d405d7772262063 | |
parent | 560d56b50df09396e03a9f06e4abcd5388a31ae9 (diff) | |
download | nq-b2fbba507f33db6e9be9282a182fc78f746287ae.tar.gz nq-b2fbba507f33db6e9be9282a182fc78f746287ae.tar.xz nq-b2fbba507f33db6e9be9282a182fc78f746287ae.zip |
tweaks
-rw-r--r-- | nq.c | 16 |
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); } } |