summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord <d@openbsd.org>1999-05-24 22:43:35 +0000
committerd <d@openbsd.org>1999-05-24 22:43:35 +0000
commit7267e82f767b1d0e56c086444e84b0b81c738c51 (patch)
treef603feff77d63f1bca065c7932e2dff8dbe12297
parentshow '(not a tty)' instead of '(null)' when wall is run with stderr not a tty. (e.g. when run from cron) (diff)
downloadwireguard-openbsd-7267e82f767b1d0e56c086444e84b0b81c738c51.tar.xz
wireguard-openbsd-7267e82f767b1d0e56c086444e84b0b81c738c51.zip
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). */
/*
* !!!