[PATCH v3 0/2] MR8983: wineserver: Request RLIMIT_NOFILE maximum allowed value.
Split from https://gitlab.winehq.org/wine/wine/-/merge_requests/8875 -- v3: wineserver: Request RLIMIT_NOFILE maximum allowed value. wineserver: Request RLIMIT_NICE maximum allowed value. https://gitlab.winehq.org/wine/wine/-/merge_requests/8983
From: Rémi Bernon <rbernon(a)codeweavers.com> For when wineserver is started separately from any wine process, where it doesn't inherit the limits otherwise requested from __wine_main. --- server/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/main.c b/server/main.c index e014ec535ff..01bec224c70 100644 --- a/server/main.c +++ b/server/main.c @@ -28,6 +28,12 @@ #include <stdlib.h> #include <sys/time.h> #include <unistd.h> +#ifdef HAVE_SYS_RESOURCE_H +# include <sys/resource.h> +#endif +#ifdef HAVE_SYS_SYSCTL_H +# include <sys/sysctl.h> +#endif #include "object.h" #include "file.h" @@ -212,6 +218,17 @@ static void sigterm_handler( int signum ) exit(1); /* make sure atexit functions get called */ } +static void set_max_limit( int limit ) +{ + struct rlimit rlimit; + + if (!getrlimit( limit, &rlimit )) + { + rlimit.rlim_cur = rlimit.rlim_max; + if (!setrlimit( limit, &rlimit )) return; + } +} + int main( int argc, char *argv[] ) { setvbuf( stderr, NULL, _IOLBF, 0 ); @@ -225,6 +242,9 @@ int main( int argc, char *argv[] ) signal( SIGQUIT, sigterm_handler ); signal( SIGTERM, sigterm_handler ); signal( SIGABRT, sigterm_handler ); +#ifdef RLIMIT_NICE + set_max_limit( RLIMIT_NICE ); +#endif sock_init(); open_master_socket(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8983
From: Rémi Bernon <rbernon(a)codeweavers.com> --- server/main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/main.c b/server/main.c index 01bec224c70..a7700129cdc 100644 --- a/server/main.c +++ b/server/main.c @@ -226,6 +226,29 @@ static void set_max_limit( int limit ) { rlimit.rlim_cur = rlimit.rlim_max; if (!setrlimit( limit, &rlimit )) return; + +#if defined(__APPLE__) && defined(RLIMIT_NOFILE) && defined(OPEN_MAX) + if (limit == RLIMIT_NOFILE) + { + unsigned int nlimit = 0; + size_t size; + + /* On Leopard, setrlimit(RLIMIT_NOFILE, ...) fails on attempts to set + * rlim_cur above OPEN_MAX (even if rlim_max > OPEN_MAX). + * + * In later versions it can be set to kern.maxfilesperproc (from + * sysctl). In Big Sur and later it can be set to rlim_max. */ + size = sizeof(nlimit); + if (sysctlbyname("kern.maxfilesperproc", &nlimit, &size, NULL, 0) != 0 || nlimit < OPEN_MAX) + rlimit.rlim_cur = OPEN_MAX; + else + rlimit.rlim_cur = nlimit; + + if (!setrlimit( limit, &rlimit )) return; + rlimit.rlim_cur = OPEN_MAX; + if (!setrlimit( limit, &rlimit )) return; + } +#endif } } @@ -242,6 +265,9 @@ int main( int argc, char *argv[] ) signal( SIGQUIT, sigterm_handler ); signal( SIGTERM, sigterm_handler ); signal( SIGABRT, sigterm_handler ); +#ifdef RLIMIT_NOFILE + set_max_limit( RLIMIT_NOFILE ); +#endif #ifdef RLIMIT_NICE set_max_limit( RLIMIT_NICE ); #endif -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8983
v3: Request RLIMIT_NICE too, remove ifdef around `set_max_limit` as it's not there in ntdll loader.c either and should then be less necessary, especially not on the platforms where we build with `-Werror`. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8983#note_116066
Fwiw these are needed for when wineserver is started separately from another wine process, and doesn't inherit the limits requested on the client side. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8983#note_116187
RLIMIT_NICE is already handled in init_threading(). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8983#note_116206
participants (2)
-
Alexandre Julliard (@julliard) -
Rémi Bernon