From: Paul Eggert Date: Fri, 2 Sep 2016 04:15:35 +0000 (-0700) Subject: Don’t create fd >= FD_SETSIZE X-Git-Tag: emacs-26.0.90~1657 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a5509099484e0762842bc2c9e914779397b91469;p=emacs.git Don’t create fd >= FD_SETSIZE This avoids a potential crash if too many subprocesses (Bug#24325). * src/process.c [HAVE_SETRLIMIT]: Include . (init_process_emacs): If ulimit -n is greater than FD_SETSIZE, set it to FD_SETSIZE. --- diff --git a/src/process.c b/src/process.c index 69d1b2a11ba..344a886be19 100644 --- a/src/process.c +++ b/src/process.c @@ -39,6 +39,10 @@ along with GNU Emacs. If not, see . */ #include #include +#ifdef HAVE_SETRLIMIT +# include +#endif + /* Are local (unix) sockets supported? */ #if defined (HAVE_SYS_UN_H) #if !defined (AF_LOCAL) && defined (AF_UNIX) @@ -7784,6 +7788,16 @@ init_process_emacs (int sockfd) catch_child_signal (); } +#ifdef HAVE_SETRLIMIT + /* Don't allocate more than FD_SETSIZE file descriptors. */ + struct rlimit rlim; + if (getrlimit (RLIMIT_NOFILE, &rlim) == 0 && FD_SETSIZE < rlim.rlim_cur) + { + rlim.rlim_cur = FD_SETSIZE; + setrlimit (RLIMIT_NOFILE, &rlim); + } +#endif + FD_ZERO (&input_wait_mask); FD_ZERO (&non_keyboard_wait_mask); FD_ZERO (&non_process_wait_mask);