summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-09-01 21:15:35 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-09-01 21:16:03 -0700
commita5509099484e0762842bc2c9e914779397b91469 (patch)
tree1f525c5b2fd175e83fb365e69334073c556f00e4 /src
parentdda2d6a311fd2a7096176e240e4e81b423eaa8e2 (diff)
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 69d1b2a11b..344a886be1 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/>. */
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifdef HAVE_SETRLIMIT
+# include <sys/resource.h>
+#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);