[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master a550909: Don’t create fd >= FD_SETSIZE
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master a550909: Don’t create fd >= FD_SETSIZE |
Date: |
Fri, 2 Sep 2016 04:19:57 +0000 (UTC) |
branch: master
commit a5509099484e0762842bc2c9e914779397b91469
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
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.
---
src/process.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/process.c b/src/process.c
index 69d1b2a..344a886 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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master a550909: Don’t create fd >= FD_SETSIZE,
Paul Eggert <=