diff options
author | brian <brian@FreeBSD.org> | 1999-08-06 08:34:42 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-08-06 08:34:42 +0000 |
commit | df1c1756e31202c817f6c35422ebc847da176a0a (patch) | |
tree | d63ccca9ddc61249d78f149e256403c60a656e69 /contrib | |
parent | 2dc04dd2d74821b0d573c8e84fd05cf7f8bfbee8 (diff) | |
download | FreeBSD-src-df1c1756e31202c817f6c35422ebc847da176a0a.zip FreeBSD-src-df1c1756e31202c817f6c35422ebc847da176a0a.tar.gz |
Set the close-on-exec flag when we lock the file we're editing.
This prevents any background sub-command executed from inheriting
the descriptor & lock (and making vi think that someone else is
editing the file when it re-edits).
Remembered from: An OpenBSD commit message from May '99
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/nvi/common/exf.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/contrib/nvi/common/exf.c b/contrib/nvi/common/exf.c index 2993b0f..6f0e160 100644 --- a/contrib/nvi/common/exf.c +++ b/contrib/nvi/common/exf.c @@ -1438,11 +1438,15 @@ file_lock(sp, name, fdp, fd, iswrite) * they are the former. There's no portable way to do this. */ errno = 0; - return (flock(fd, LOCK_EX | LOCK_NB) ? errno == EAGAIN + if (!flock(fd, LOCK_EX | LOCK_NB)) { + fcntl(fd, F_SETFD, 1); + return (LOCK_SUCCESS); + } + return (errno == EAGAIN #ifdef EWOULDBLOCK || errno == EWOULDBLOCK #endif - ? LOCK_UNAVAIL : LOCK_FAILED : LOCK_SUCCESS); + ? LOCK_UNAVAIL : LOCK_FAILED); #endif #ifdef HAVE_LOCK_FCNTL /* Gag me. We've got fcntl(2). */ { @@ -1470,8 +1474,11 @@ file_lock(sp, name, fdp, fd, iswrite) } errno = 0; - if (!fcntl(fd, F_SETLK, &arg)) + if (!fcntl(fd, F_SETLK, &arg)) { + fcntl(fd, F_SETFD, 1); return (LOCK_SUCCESS); + } + if (didopen) { sverrno = errno; (void)close(fd); |