diff options
Diffstat (limited to 'other/bootstrap_daemon/src')
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 5dba9dcc..88f45494 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -27,11 +27,14 @@ | |||
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | // system provided | 29 | // system provided |
30 | #include <sys/resource.h> | ||
30 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
31 | #include <signal.h> // for POSIX sigaction(2) | 32 | #include <signal.h> // system header, rather than C, because we need it for POSIX sigaction(2) |
32 | #include <unistd.h> | 33 | #include <unistd.h> |
33 | 34 | ||
34 | // C | 35 | // C |
36 | #include <assert.h> | ||
37 | #include <stdint.h> | ||
35 | #include <stdio.h> | 38 | #include <stdio.h> |
36 | #include <stdlib.h> | 39 | #include <stdlib.h> |
37 | #include <string.h> | 40 | #include <string.h> |
@@ -424,6 +427,30 @@ int main(int argc, char *argv[]) | |||
424 | 427 | ||
425 | if (tcp_server != nullptr) { | 428 | if (tcp_server != nullptr) { |
426 | log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); | 429 | log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); |
430 | |||
431 | struct rlimit limit; | ||
432 | |||
433 | const rlim_t rlim_suggested = 32768; | ||
434 | const rlim_t rlim_min = 4096; | ||
435 | |||
436 | assert(rlim_suggested >= rlim_min); | ||
437 | |||
438 | if (!getrlimit(RLIMIT_NOFILE, &limit)) { | ||
439 | if (limit.rlim_cur < limit.rlim_max) { | ||
440 | // Some systems have a hard limit of over 1000000 open file descriptors, so let's cap it at something reasonable | ||
441 | // so that we don't set it to an unreasonably high number. | ||
442 | limit.rlim_cur = limit.rlim_max > rlim_suggested ? rlim_suggested : limit.rlim_max; | ||
443 | setrlimit(RLIMIT_NOFILE, &limit); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | if (!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur < rlim_min) { | ||
448 | log_write(LOG_LEVEL_WARNING, | ||
449 | "Current limit on the number of files this process can open (%ju) is rather low for the proper functioning of the TCP server. " | ||
450 | "Consider raising the limit to at least %ju or the recommended %ju. " | ||
451 | "Continuing using the current limit (%ju).\n", | ||
452 | (uintmax_t)limit.rlim_cur, (uintmax_t)rlim_min, (uintmax_t)rlim_suggested, (uintmax_t)limit.rlim_cur); | ||
453 | } | ||
427 | } else { | 454 | } else { |
428 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); | 455 | log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); |
429 | kill_onion_announce(onion_a); | 456 | kill_onion_announce(onion_a); |