aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-09-01 21:15:35 -0700
committerPaul Eggert2016-09-01 21:16:03 -0700
commita5509099484e0762842bc2c9e914779397b91469 (patch)
tree1f525c5b2fd175e83fb365e69334073c556f00e4 /src
parentdda2d6a311fd2a7096176e240e4e81b423eaa8e2 (diff)
downloademacs-a5509099484e0762842bc2c9e914779397b91469.tar.gz
emacs-a5509099484e0762842bc2c9e914779397b91469.zip
Don’t create fd >= FD_SETSIZE
This avoids a potential crash if too many subprocesses (Bug#24325). * src/process.c [HAVE_SETRLIMIT]: Include <sys/resource.h>. (init_process_emacs): If ulimit -n is greater than FD_SETSIZE, set it to FD_SETSIZE.
Diffstat (limited to 'src')
-rw-r--r--src/process.c14
1 files changed, 14 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. */
39#include <netinet/in.h> 39#include <netinet/in.h>
40#include <arpa/inet.h> 40#include <arpa/inet.h>
41 41
42#ifdef HAVE_SETRLIMIT
43# include <sys/resource.h>
44#endif
45
42/* Are local (unix) sockets supported? */ 46/* Are local (unix) sockets supported? */
43#if defined (HAVE_SYS_UN_H) 47#if defined (HAVE_SYS_UN_H)
44#if !defined (AF_LOCAL) && defined (AF_UNIX) 48#if !defined (AF_LOCAL) && defined (AF_UNIX)
@@ -7784,6 +7788,16 @@ init_process_emacs (int sockfd)
7784 catch_child_signal (); 7788 catch_child_signal ();
7785 } 7789 }
7786 7790
7791#ifdef HAVE_SETRLIMIT
7792 /* Don't allocate more than FD_SETSIZE file descriptors. */
7793 struct rlimit rlim;
7794 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0 && FD_SETSIZE < rlim.rlim_cur)
7795 {
7796 rlim.rlim_cur = FD_SETSIZE;
7797 setrlimit (RLIMIT_NOFILE, &rlim);
7798 }
7799#endif
7800
7787 FD_ZERO (&input_wait_mask); 7801 FD_ZERO (&input_wait_mask);
7788 FD_ZERO (&non_keyboard_wait_mask); 7802 FD_ZERO (&non_keyboard_wait_mask);
7789 FD_ZERO (&non_process_wait_mask); 7803 FD_ZERO (&non_process_wait_mask);