diff options
| -rw-r--r-- | src/split_for_sort.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/split_for_sort.c b/src/split_for_sort.c index bb586cf..0dd8e32 100644 --- a/src/split_for_sort.c +++ b/src/split_for_sort.c @@ -13,6 +13,7 @@ #include <string.h> #include <ctype.h> #include <errno.h> +#include <sys/resource.h> #include <sys/stat.h> #include "output.h" @@ -45,6 +46,26 @@ struct list_node *get_node(struct list_head *list, char *name); void destroy_list(struct list_head *list); void fflush_list(struct list_head *list); void print_list(struct list_head *list, FILE *out); +int set_nofile_limit_to_hard(); + + + +int set_nofile_limit_to_hard() { + struct rlimit lim; + if (getrlimit(RLIMIT_NOFILE , &lim) != 0) { + LOGERR("ERROR: Failed to get RLIMIT_NOFILE: %s (errno %d)\n", + strerror(errno), errno); + return -1; + } + lim.rlim_cur = lim.rlim_max; + if (setrlimit(RLIMIT_NOFILE , &lim) != 0) { + LOGERR("ERROR: Failed to set RLIMIT_NOFILE: %s (errno %d)\n", + strerror(errno), errno); + return -1; + } + return 0; +} + void destroy_list(struct list_head *list) { struct list_node *n = NULL, *b = NULL; @@ -341,6 +362,10 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } + /* modern Linux distributions set the soft limit to 1024 file descriptors, + * this may not be sufficient, therefore increase to the hard limit */ + set_nofile_limit_to_hard(); + splitlength = strtoull(argv[2], NULL, 10); if (splitlength == 0) { LOGERR("ERROR: Failed to read valid length from argument '%s' base 10 number >=1 expected\n", argv[2]); |
