diff --git a/criu/crtools.c b/criu/crtools.c index 16546efb6..3d8fa04b4 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -19,6 +19,9 @@ #include +#include +#include + #include "int.h" #include "page.h" #include "common/compiler.h" @@ -231,6 +234,20 @@ static void soccr_print_on_level(unsigned int loglevel, const char *format, ...) va_end(args); } +static void rlimit_unlimit_nofile_self(void) +{ + struct rlimit new; + + new.rlim_cur = kdat.sysctl_nr_open; + new.rlim_max = kdat.sysctl_nr_open; + + if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) { + pr_perror("rlimir: Can't setup RLIMIT_NOFILE for self"); + return; + } else + pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n"); +} + int main(int argc, char *argv[], char *envp[]) { @@ -339,6 +356,24 @@ int main(int argc, char *argv[], char *envp[]) init_opts(); + /* + * Service fd engine implies that file descritprs + * used won't be borrowed by the rest of the code + * and default 1024 limit is not enough for high + * loaded test/containers. Thus use kdat engine + * to fetch current system level limit for numbers + * of files allowed to open up and lift up own + * limits. + * + * Note we have to do it before the service fd + * get inited and we dont exit with errors here + * because in worst scenario where clash of fd + * happen we simply exit with explicit error + * during real action stage. + */ + if (!kerndat_files_stat(true)) + rlimit_unlimit_nofile_self(); + if (init_service_fd()) return 1;