diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-11-14 20:23:57 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-11-14 20:23:57 +0000 |
commit | 856819cc8cd3e47cca9f0eb6a63a5203d17b3bfd (patch) | |
tree | 69c1ac9205dd748a59b2aa3066d19ee33f5ca3e4 /usr.bin/vi/common | |
parent | 2b917a9c98ca823bee8ac280df735bb6424ed3e1 (diff) |
from natano:
The vi editor contains code for two different file locking methods -
one using flock(), the other using fcntl(). The fcntl method is unused
and has severe limitations (as described in a code comment). Let's
remove it for sake of readibility.
Diffstat (limited to 'usr.bin/vi/common')
-rw-r--r-- | usr.bin/vi/common/exf.c | 69 |
1 files changed, 1 insertions, 68 deletions
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c index 8fb63d4b94e..c7aefb308ae 100644 --- a/usr.bin/vi/common/exf.c +++ b/usr.bin/vi/common/exf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exf.c,v 1.31 2014/11/12 16:29:04 millert Exp $ */ +/* $OpenBSD: exf.c,v 1.32 2014/11/14 20:23:56 tedu Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -1379,23 +1379,6 @@ set_alt_name(SCR *sp, char *name) * file_lock -- * Get an exclusive lock on a file. * - * XXX - * The default locking is flock(2) style, not fcntl(2). The latter is - * known to fail badly on some systems, and its only advantage is that - * it occasionally works over NFS. - * - * Furthermore, the semantics of fcntl(2) are wrong. The problems are - * two-fold: you can't close any file descriptor associated with the file - * without losing all of the locks, and you can't get an exclusive lock - * unless you have the file open for writing. Someone ought to be shot, - * but it's probably too late, they may already have reproduced. To get - * around these problems, nvi opens the files for writing when it can and - * acquires a second file descriptor when it can't. The recovery files - * are examples of the former, they're always opened for writing. The DB - * files can't be opened for writing because the semantics of DB are that - * files opened for writing are flushed back to disk when the DB session - * is ended. So, in that case we have to acquire an extra file descriptor. - * * PUBLIC: lockr_t file_lock(SCR *, char *, int *, int, int); */ lockr_t @@ -1408,7 +1391,6 @@ file_lock(SCR *sp, char *name, int *fdp, int fd, int iswrite) if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) msgq_str(sp, M_SYSERR, name, "%s"); -#ifdef HAVE_LOCK_FLOCK /* Hurrah! We've got flock(2). */ /* * !!! * We need to distinguish a lock not being available for the file @@ -1420,53 +1402,4 @@ file_lock(SCR *sp, char *name, int *fdp, int fd, int iswrite) return (flock(fd, LOCK_EX | LOCK_NB) ? errno == EAGAIN || errno == EWOULDBLOCK ? LOCK_UNAVAIL : LOCK_FAILED : LOCK_SUCCESS); -#endif -#ifdef HAVE_LOCK_FCNTL /* Gag me. We've got fcntl(2). */ -{ - struct flock arg; - int didopen, sverrno; - - arg.l_type = F_WRLCK; - arg.l_whence = 0; /* SEEK_SET */ - arg.l_start = arg.l_len = 0; - arg.l_pid = 0; - - /* - * If the file descriptor isn't opened for writing, it must fail. - * If we fail because we can't get a read/write file descriptor, - * we return LOCK_SUCCESS, believing that the file is readonly - * and that will be sufficient to warn the user. - */ - if (!iswrite) { - if (name == NULL || fdp == NULL) - return (LOCK_FAILED); - if ((fd = open(name, O_RDWR, 0)) == -1) - return (LOCK_SUCCESS); - *fdp = fd; - didopen = 1; - } - - errno = 0; - if (!fcntl(fd, F_SETLK, &arg)) - return (LOCK_SUCCESS); - if (didopen) { - sverrno = errno; - (void)close(fd); - errno = sverrno; - } - - /* - * !!! - * We need to distinguish a lock not being available for the file - * from the file system not supporting locking. Fcntl is documented - * as returning EACCESS and EAGAIN; add EWOULDBLOCK for good measure, - * and assume they are the former. There's no portable way to do this. - */ - return (errno == EACCES || errno == EAGAIN || errno == EWOULDBLOCK ? - LOCK_UNAVAIL : LOCK_FAILED); -} -#endif -#if !defined(HAVE_LOCK_FLOCK) && !defined(HAVE_LOCK_FCNTL) - return (LOCK_SUCCESS); -#endif } |