4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Vim doesn't close file descriptors when forking and executing
12 another command, e.g., ":shell".
13 Solution: Use FD_CLOEXEC when available. (James Vega)
14 Files: src/auto/configure, src/config.h.in, src/configure.in,
15 src/ex_cmdds2.c, src/fileio.c, src/memfile.c, src/memline.c
18 *** ../vim-7.2.299/src/auto/configure 2009-11-17 12:08:48.000000000 +0100
19 --- src/auto/configure 2009-11-17 13:09:03.000000000 +0100
26 + { $as_echo "$as_me:$LINENO: checking for FD_CLOEXEC" >&5
27 + $as_echo_n "checking for FD_CLOEXEC... " >&6; }
28 + cat >conftest.$ac_ext <<_ACEOF
31 + cat confdefs.h >>conftest.$ac_ext
32 + cat >>conftest.$ac_ext <<_ACEOF
33 + /* end confdefs.h. */
40 + int flag = FD_CLOEXEC;
45 + rm -f conftest.$ac_objext
46 + if { (ac_try="$ac_compile"
48 + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
49 + *) ac_try_echo=$ac_try;;
51 + eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
52 + $as_echo "$ac_try_echo") >&5
53 + (eval "$ac_compile") 2>conftest.er1
55 + grep -v '^ *+' conftest.er1 >conftest.err
57 + cat conftest.err >&5
58 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
59 + (exit $ac_status); } && {
60 + test -z "$ac_c_werror_flag" ||
61 + test ! -s conftest.err
62 + } && test -s conftest.$ac_objext; then
63 + { $as_echo "$as_me:$LINENO: result: yes" >&5
64 + $as_echo "yes" >&6; }; cat >>confdefs.h <<\_ACEOF
65 + #define HAVE_FD_CLOEXEC 1
69 + $as_echo "$as_me: failed program was:" >&5
70 + sed 's/^/| /' conftest.$ac_ext >&5
72 + { $as_echo "$as_me:$LINENO: result: not usable" >&5
73 + $as_echo "not usable" >&6; }
76 + rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
78 { $as_echo "$as_me:$LINENO: checking for rename" >&5
79 $as_echo_n "checking for rename... " >&6; }
80 cat >conftest.$ac_ext <<_ACEOF
81 *** ../vim-7.2.299/src/config.h.in 2009-11-17 12:08:48.000000000 +0100
82 --- src/config.h.in 2009-11-17 13:01:36.000000000 +0100
87 /* Define if you want XSMP interaction as well as vanilla swapfile safety */
88 #undef USE_XSMP_INTERACT
90 + /* Define if fcntl()'s F_SETFD command knows about FD_CLOEXEC */
91 + #undef HAVE_FD_CLOEXEC
92 *** ../vim-7.2.299/src/configure.in 2009-11-17 12:08:48.000000000 +0100
93 --- src/configure.in 2009-11-17 13:01:36.000000000 +0100
100 + dnl make sure the FD_CLOEXEC flag for fcntl()'s F_SETFD command is known
101 + AC_MSG_CHECKING(for FD_CLOEXEC)
104 + # include <fcntl.h>
106 + [ int flag = FD_CLOEXEC;],
107 + AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FD_CLOEXEC),
108 + AC_MSG_RESULT(not usable))
110 dnl rename needs to be checked separately to work on Nextstep with cc
111 AC_MSG_CHECKING(for rename)
112 AC_TRY_LINK([#include <stdio.h>], [rename("this", "that")],
113 *** ../vim-7.2.299/src/fileio.c 2009-11-17 14:57:19.000000000 +0100
114 --- src/fileio.c 2009-11-17 13:22:06.000000000 +0100
119 if (!read_buffer && !read_stdin)
120 close(fd); /* errors are ignored */
121 + #ifdef HAVE_FD_CLOEXEC
124 + int fdflags = fcntl(fd, F_GETFD);
125 + if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
126 + fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
132 *** ../vim-7.2.299/src/memfile.c 2008-07-13 19:39:39.000000000 +0200
133 --- src/memfile.c 2009-11-17 13:22:15.000000000 +0100
140 + #ifdef HAVE_FD_CLOEXEC
141 + int fdflags = fcntl(mfp->mf_fd, F_GETFD);
142 + if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
143 + fcntl(mfp->mf_fd, F_SETFD, fdflags | FD_CLOEXEC);
146 mch_copy_sec(fname, mfp->mf_fname);
148 *** ../vim-7.2.299/src/memline.c 2009-11-03 15:32:58.000000000 +0100
149 --- src/memline.c 2009-11-17 13:21:40.000000000 +0100
152 dp->db_index[0] = --dp->db_txt_start; /* at end of block */
153 dp->db_free -= 1 + INDEX_SIZE;
154 dp->db_line_count = 1;
155 ! *((char_u *)dp + dp->db_txt_start) = NUL; /* emtpy line */
160 dp->db_index[0] = --dp->db_txt_start; /* at end of block */
161 dp->db_free -= 1 + INDEX_SIZE;
162 dp->db_line_count = 1;
163 ! *((char_u *)dp + dp->db_txt_start) = NUL; /* empty line */
170 EMSG(_("E301: Oops, lost the swap file!!!"));
173 + #ifdef HAVE_FD_CLOEXEC
175 + int fdflags = fcntl(mfp->mf_fd, F_GETFD);
176 + if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
177 + fcntl(mfp->mf_fd, F_SETFD, fdflags | FD_CLOEXEC);
182 EMSG(_("E302: Could not rename swap file"));
183 *** ../vim-7.2.299/src/version.c 2009-11-17 16:08:12.000000000 +0100
184 --- src/version.c 2009-11-17 17:09:43.000000000 +0100
188 { /* Add new patch number below this line */
196 Ceci n'est pas une pipe.
198 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
199 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
200 \\\ download, build and distribute -- http://www.A-A-P.org ///
201 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///