diff options
author | csjp <csjp@FreeBSD.org> | 2005-10-05 22:02:07 +0000 |
---|---|---|
committer | csjp <csjp@FreeBSD.org> | 2005-10-05 22:02:07 +0000 |
commit | 4c0da01019968cfc8e5cad523bcece0cb030c06c (patch) | |
tree | 944fc36f0110c3499b101199a55da428672e6a8b /usr.bin | |
parent | 3ad67431fb8a7aff6ab8e9474b16b8c88ecfae6e (diff) | |
download | FreeBSD-src-4c0da01019968cfc8e5cad523bcece0cb030c06c.zip FreeBSD-src-4c0da01019968cfc8e5cad523bcece0cb030c06c.tar.gz |
Un-break handling of -t 0 which was broken in my previous commit.
Add a flags argument to wait_for_lock so that O_NONBLOCK can be
passed to open if a user doesn't want the open to sleep until the
lock becomes available.
Submitted by: Amir Shalem (partially modified)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/lockf/lockf.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c index de4aac9..69da1c9 100644 --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -42,7 +42,7 @@ static void cleanup(void); static void killed(int sig); static void timeout(int sig); static void usage(void); -static int wait_for_lock(const char *name); +static int wait_for_lock(const char *name, int flags); static const char *lockname; static int lockfd = -1; @@ -105,8 +105,9 @@ main(int argc, char **argv) alarm(waitsec); } + lockfd = wait_for_lock(lockname, O_NONBLOCK); while (lockfd == -1 && !timed_out && waitsec != 0) - lockfd = wait_for_lock(lockname); + lockfd = wait_for_lock(lockname, 0); if (waitsec > 0) alarm(0); @@ -190,12 +191,12 @@ usage(void) * Wait until it might be possible to acquire a lock on the given file. */ static int -wait_for_lock(const char *name) +wait_for_lock(const char *name, int flags) { int fd; - if ((fd = open(name, O_CREAT|O_RDONLY|O_EXLOCK, 0666)) == -1) { - if (errno == ENOENT || errno == EINTR) + if ((fd = open(name, O_CREAT|O_RDONLY|O_EXLOCK|flags, 0666)) == -1) { + if (errno == ENOENT || errno == EINTR || errno == EAGAIN) return (-1); err(EX_CANTCREAT, "cannot open %s", name); } |