aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-11-06 22:55:30 -0800
committerPaul Eggert2016-11-06 22:56:36 -0800
commitb6d9613df83813609ef80da45975e70954d1fb6d (patch)
treebf05ac8bbd5a91b40fb23a8d84dce66360884211 /src
parentf1d19d1445a8e7d4ee0d13edb8ed99e222603086 (diff)
downloademacs-b6d9613df83813609ef80da45975e70954d1fb6d.tar.gz
emacs-b6d9613df83813609ef80da45975e70954d1fb6d.zip
Restore file descriptor limit in subprocesses
Problem reported by Philipp Stephani (Bug#24869). * src/callproc.c (child_setup) [!DOS_NT]: Call restore_nofile_limit in the child. * src/process.c (nofile_limit) [HAVE_SETRLIMIT]: New static var. (restore_nofile_limit): New function. (init_process_emacs) [HAVE_SETRLIMIT]: Set the new var.
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c3
-rw-r--r--src/process.c27
-rw-r--r--src/process.h1
3 files changed, 27 insertions, 4 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 8ed28556e0d..dc3ca4ac102 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1315,6 +1315,9 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1315#else /* not WINDOWSNT */ 1315#else /* not WINDOWSNT */
1316 1316
1317#ifndef MSDOS 1317#ifndef MSDOS
1318
1319 restore_nofile_limit ();
1320
1318 /* Redirect file descriptors and clear the close-on-exec flag on the 1321 /* Redirect file descriptors and clear the close-on-exec flag on the
1319 redirected ones. IN, OUT, and ERR are close-on-exec so they 1322 redirected ones. IN, OUT, and ERR are close-on-exec so they
1320 need not be closed explicitly. */ 1323 need not be closed explicitly. */
diff --git a/src/process.c b/src/process.c
index d27b57d560f..d68c930dd6f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -42,6 +42,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
42 42
43#ifdef HAVE_SETRLIMIT 43#ifdef HAVE_SETRLIMIT
44# include <sys/resource.h> 44# include <sys/resource.h>
45
46/* If NOFILE_LIMIT.rlim_cur is greater than FD_SETSIZE, then
47 NOFILE_LIMIT is the initial limit on the number of open files,
48 which should be restored in child processes. */
49static struct rlimit nofile_limit;
45#endif 50#endif
46 51
47/* Are local (unix) sockets supported? */ 52/* Are local (unix) sockets supported? */
@@ -7770,6 +7775,17 @@ catch_child_signal (void)
7770} 7775}
7771#endif /* subprocesses */ 7776#endif /* subprocesses */
7772 7777
7778/* Limit the number of open files to the value it had at startup. */
7779
7780void
7781restore_nofile_limit (void)
7782{
7783#ifdef HAVE_SETRLIMIT
7784 if (FD_SETSIZE < nofile_limit.rlim_cur)
7785 setrlimit (RLIMIT_NOFILE, &nofile_limit);
7786#endif
7787}
7788
7773 7789
7774/* This is not called "init_process" because that is the name of a 7790/* This is not called "init_process" because that is the name of a
7775 Mach system call, so it would cause problems on Darwin systems. */ 7791 Mach system call, so it would cause problems on Darwin systems. */
@@ -7796,12 +7812,15 @@ init_process_emacs (int sockfd)
7796 } 7812 }
7797 7813
7798#ifdef HAVE_SETRLIMIT 7814#ifdef HAVE_SETRLIMIT
7799 /* Don't allocate more than FD_SETSIZE file descriptors. */ 7815 /* Don't allocate more than FD_SETSIZE file descriptors for Emacs itself. */
7800 struct rlimit rlim; 7816 if (getrlimit (RLIMIT_NOFILE, &nofile_limit) != 0)
7801 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0 && FD_SETSIZE < rlim.rlim_cur) 7817 nofile_limit.rlim_cur = 0;
7818 else if (FD_SETSIZE < nofile_limit.rlim_cur)
7802 { 7819 {
7820 struct rlimit rlim = nofile_limit;
7803 rlim.rlim_cur = FD_SETSIZE; 7821 rlim.rlim_cur = FD_SETSIZE;
7804 setrlimit (RLIMIT_NOFILE, &rlim); 7822 if (setrlimit (RLIMIT_NOFILE, &rlim) != 0)
7823 nofile_limit.rlim_cur = 0;
7805 } 7824 }
7806#endif 7825#endif
7807 7826
diff --git a/src/process.h b/src/process.h
index 9926050b9c3..24c628231a0 100644
--- a/src/process.h
+++ b/src/process.h
@@ -265,6 +265,7 @@ extern void delete_read_fd (int fd);
265extern void add_write_fd (int fd, fd_callback func, void *data); 265extern void add_write_fd (int fd, fd_callback func, void *data);
266extern void delete_write_fd (int fd); 266extern void delete_write_fd (int fd);
267extern void catch_child_signal (void); 267extern void catch_child_signal (void);
268extern void restore_nofile_limit (void);
268 269
269#ifdef WINDOWSNT 270#ifdef WINDOWSNT
270extern Lisp_Object network_interface_list (void); 271extern Lisp_Object network_interface_list (void);