From 1a875079809eb31d2a080e005d76f4f634ebb771 Mon Sep 17 00:00:00 2001 From: David Leonard Date: Mon, 24 May 1999 22:43:36 +0000 Subject: 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. --- usr.bin/vi/common/exf.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'usr.bin/vi/common') 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). */ /* * !!! -- cgit v1.2.3