From: Rémi Bernon rbernon@codeweavers.com
--- dlls/ntdll/unix/loader.c | 3 +++ dlls/ntdll/unix/server.c | 14 ++++++++++++++ include/wine/server_protocol.h | 4 +++- server/process.h | 1 + server/protocol.def | 1 + server/request.h | 3 ++- server/thread.c | 7 +++++++ server/trace.c | 1 + 8 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index aa120ae38ec..9dd6c672336 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -2125,6 +2125,9 @@ DECLSPEC_EXPORT void __wine_main( int argc, char *argv[], char *envp[] ) #ifdef RLIMIT_AS set_max_limit( RLIMIT_AS ); #endif +#ifdef RLIMIT_NICE + set_max_limit( RLIMIT_NICE ); +#endif
virtual_init(); init_environment( argc, argv, envp ); diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index 7211457387c..bfb14173d60 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -53,6 +53,9 @@ # include <sys/prctl.h> #endif #include <sys/stat.h> +#ifdef HAVE_SYS_RESOURCE_H +# include <sys/resource.h> +#endif #ifdef HAVE_SYS_SYSCALL_H # include <sys/syscall.h> #endif @@ -1552,6 +1555,8 @@ size_t server_init_process(void) struct sigaction sig_act; size_t info_size; DWORD pid, tid; + struct rlimit rlimit; + int nice_limit = 0;
server_pid = -1; if (env_socket) @@ -1613,10 +1618,19 @@ size_t server_init_process(void)
reply_pipe = init_thread_pipe();
+#ifdef RLIMIT_NICE + if (!getrlimit( RLIMIT_NICE, &rlimit )) + { + if (rlimit.rlim_cur <= 40) nice_limit = 20 - rlimit.rlim_cur; + else if (rlimit.rlim_cur == -1 /* RLIMIT_INFINITY */) nice_limit = -20; + } +#endif + SERVER_START_REQ( init_first_thread ) { req->unix_pid = getpid(); req->unix_tid = get_unix_tid(); + req->nice_limit = nice_limit; req->reply_fd = reply_pipe; req->wait_fd = ntdll_get_thread_data()->wait_fd[1]; req->debug_level = (TRACE_ON(server) != 0); diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index a392b532f4e..f2fb0474803 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -988,6 +988,8 @@ struct init_first_thread_request int debug_level; int reply_fd; int wait_fd; + char nice_limit; + char __pad_33[7]; }; struct init_first_thread_reply { @@ -6504,7 +6506,7 @@ union generic_reply
/* ### protocol_version begin ### */
-#define SERVER_PROTOCOL_VERSION 784 +#define SERVER_PROTOCOL_VERSION 785
/* ### protocol_version end ### */
diff --git a/server/process.h b/server/process.h index 97e0d455ece..203a97d6682 100644 --- a/server/process.h +++ b/server/process.h @@ -50,6 +50,7 @@ struct process timeout_t sigkill_delay; /* delay before final SIGKILL */ unsigned short machine; /* client machine type */ int unix_pid; /* Unix pid for final SIGKILL */ + int nice_limit; /* RLIMIT_NICE of the process */ int exit_code; /* process exit code */ int running_threads; /* number of threads running in this process */ timeout_t start_time; /* absolute time at process start */ diff --git a/server/protocol.def b/server/protocol.def index e9195df6b65..fb4aa32ad18 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -969,6 +969,7 @@ typedef struct int debug_level; /* new debug level */ int reply_fd; /* fd for reply pipe */ int wait_fd; /* fd for blocking calls pipe */ + char nice_limit; /* RLIMIT_NICE of new thread */ @REPLY process_id_t pid; /* process id of the new thread's process */ thread_id_t tid; /* thread id of the new thread */ diff --git a/server/request.h b/server/request.h index d6043c5fdc3..c2dc4a8ada4 100644 --- a/server/request.h +++ b/server/request.h @@ -786,7 +786,8 @@ C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, unix_tid) == 16 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, debug_level) == 20 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, reply_fd) == 24 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, wait_fd) == 28 ); -C_ASSERT( sizeof(struct init_first_thread_request) == 32 ); +C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, nice_limit) == 32 ); +C_ASSERT( sizeof(struct init_first_thread_request) == 40 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, pid) == 8 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, tid) == 12 ); C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, server_start) == 16 ); diff --git a/server/thread.c b/server/thread.c index 5c039828912..dcc90aded09 100644 --- a/server/thread.c +++ b/server/thread.c @@ -37,6 +37,12 @@ #define _WITH_CPU_SET_T #include <sched.h> #endif +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif
#include "ntstatus.h" #define WIN32_NO_STATUS @@ -1423,6 +1429,7 @@ DECL_HANDLER(init_first_thread)
current->unix_pid = process->unix_pid = req->unix_pid; current->unix_tid = req->unix_tid; + process->nice_limit = req->nice_limit;
if (!process->parent_id) process->affinity = current->affinity = get_thread_affinity( current ); diff --git a/server/trace.c b/server/trace.c index 55ccefa1746..5a099071752 100644 --- a/server/trace.c +++ b/server/trace.c @@ -1472,6 +1472,7 @@ static void dump_init_first_thread_request( const struct init_first_thread_reque fprintf( stderr, ", debug_level=%d", req->debug_level ); fprintf( stderr, ", reply_fd=%d", req->reply_fd ); fprintf( stderr, ", wait_fd=%d", req->wait_fd ); + fprintf( stderr, ", nice_limit=%c", req->nice_limit ); }
static void dump_init_first_thread_reply( const struct init_first_thread_reply *req )