summaryrefslogtreecommitdiffstats
path: root/lib/libutil/flopen.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2007-05-10 14:52:57 +0000
committerdes <des@FreeBSD.org>2007-05-10 14:52:57 +0000
commit50d71f5464b9302c59bba4260b8b48f2ebef7142 (patch)
treef0b7fc85fde1f8d40a730e691489335d8a05a91e /lib/libutil/flopen.c
parent5d25ea6b6214552539112dbc8d1bdc8f79460dd6 (diff)
downloadFreeBSD-src-50d71f5464b9302c59bba4260b8b48f2ebef7142.zip
FreeBSD-src-50d71f5464b9302c59bba4260b8b48f2ebef7142.tar.gz
DTRT when O_NONBLOCK is specified.
MFC after: 3 weeks
Diffstat (limited to 'lib/libutil/flopen.c')
-rw-r--r--lib/libutil/flopen.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libutil/flopen.c b/lib/libutil/flopen.c
index 66d4e47..39cb81f 100644
--- a/lib/libutil/flopen.c
+++ b/lib/libutil/flopen.c
@@ -39,29 +39,32 @@ __FBSDID("$FreeBSD$");
int
flopen(const char *path, int flags, ...)
{
+ int fd, operation, serrno;
struct stat sb, fsb;
mode_t mode;
- int fd, serrno;
#ifdef O_EXLOCK
flags &= ~O_EXLOCK;
#endif
+ mode = 0;
if (flags & O_CREAT) {
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, int); /* mode_t promoted to int */
va_end(ap);
- } else {
- mode = 0;
}
+ operation = LOCK_EX;
+ if (flags & O_NONBLOCK)
+ operation |= LOCK_NB;
+
for (;;) {
if ((fd = open(path, flags, mode)) == -1)
/* non-existent or no access */
return (-1);
- if (flock(fd, LOCK_EX) == -1) {
+ if (flock(fd, operation) == -1) {
/* unsupported or interrupted */
serrno = errno;
close(fd);
OpenPOWER on IntegriCloud