summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1999-05-24 22:43:36 +0000
committerDavid Leonard <d@cvs.openbsd.org>1999-05-24 22:43:36 +0000
commit1a875079809eb31d2a080e005d76f4f634ebb771 (patch)
tree5f73c255777ec7c4308985a55fb005c583e2e0f4
parenta3da61d7add650116ef2599a85d77a28aa36cae4 (diff)
set the close-on-exec flag for newly opened files
Reason: vi uses flock to help you notice when you are already editing a file. But, when using :shell or :! the fdesc for the locked file is inherited by the subprocess. This means that if you (say) do a :!xterm& and then quit vi, the fdesc is kept open by the xterm and the lock is never released. future vi's on that file will then complain. I sent this off to bostic.com a long time ago but have as yet heard nothing.
-rw-r--r--usr.bin/vi/common/exf.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c
index 574a16aab3b..dd0eba7fd87 100644
--- a/usr.bin/vi/common/exf.c
+++ b/usr.bin/vi/common/exf.c
@@ -1436,6 +1436,10 @@ file_lock(sp, name, fdp, fd, iswrite)
if (!O_ISSET(sp, O_LOCKFILES))
return (LOCK_SUCCESS);
+ /* Set close-on-exec flag so locks are not inherited by shell cmd. */
+ if (fcntl(fd, F_SETFD, 1) == -1)
+ msgq_str(sp, M_SYSERR, name, "%s");
+
#ifdef HAVE_LOCK_FLOCK /* Hurrah! We've got flock(2). */
/*
* !!!