diff options
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 27 |
1 files changed, 23 insertions, 4 deletions
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. */ | ||
| 49 | static 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 | |||
| 7780 | void | ||
| 7781 | restore_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 | ||