-- v2: ntdll: Use posix_spawn() to start the server. ntdll: Factor out generating possible paths to wineserver.
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/loader.c | 95 +++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 26 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index aa120ae38ec..883288960d6 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -546,47 +546,88 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i
/*********************************************************************** - * exec_wineserver + * next_wineserver_path * - * Exec a new wine server. + * Return possible paths to the server. */ -static void exec_wineserver( char **argv ) +static char *next_wineserver_path( char **pathcopy ) { - char *path; + static int step = 0;
- if (build_dir) + switch (step) { - if (!is_win64) /* look for 64-bit server */ + case 0: + if (build_dir && !is_win64) /* look for 64-bit server */ { - char *loader = realpath_dirname( build_path( build_dir, "loader/wine64" )); + char *loader_relative = build_path( build_dir, "loader/wine64" ); + char *loader = realpath_dirname( loader_relative ); + free( loader_relative ); if (loader) { - argv[0] = build_path( loader, "../server/wineserver" ); - execv( argv[0], argv ); + char *ret = build_path( loader, "../server/wineserver" ); + free( loader ); + step = 1; + return ret; } } - argv[0] = build_path( build_dir, "server/wineserver" ); - execv( argv[0], argv ); - return; - } + /* fallthrough */
- argv[0] = build_path( bin_dir, "wineserver" ); - execv( argv[0], argv ); + case 1: + if (build_dir) + { + step = 2; + return build_path( build_dir, "server/wineserver" ); + } + /* fallthrough */
- argv[0] = getenv( "WINESERVER" ); - if (argv[0]) execv( argv[0], argv ); + case 2: + if (build_dir) + return NULL; + /* fallthrough */
- if ((path = getenv( "PATH" ))) - { - for (path = strtok( strdup( path ), ":" ); path; path = strtok( NULL, ":" )) + case 3: + step = 4; + return build_path( bin_dir, "wineserver" ); + + case 4: + if (getenv( "WINESERVER" )) { - argv[0] = build_path( path, "wineserver" ); - execvp( argv[0], argv ); + step = 5; + return strdup( getenv( "WINESERVER" ) ); } - } + /* fallthrough */ + + case 5: + if (getenv( "PATH" )) + *pathcopy = strdup( getenv( "PATH" ) ); + + step = 6; + if (*pathcopy) + { + char *path = strtok( *pathcopy, ":" ); + if (path) + return build_path( path, "wineserver" ); + } + /* fallthrough */ + + case 6: + if (*pathcopy) + { + char *path = strtok( NULL, ":" ); + if (path) + return build_path( path, "wineserver" ); + else + step = 7; + } + /* fallthrough */
- argv[0] = build_path( BINDIR, "wineserver" ); - execv( argv[0], argv ); + case 7: + step = 8; + return build_path( BINDIR, "wineserver" ); + + default: + return NULL; + } }
@@ -604,13 +645,15 @@ void start_server( BOOL debug ) if (!started) { int status; + char *pathcopy = NULL; int pid = fork(); if (pid == -1) fatal_error( "fork: %s", strerror(errno) ); if (!pid) { argv[1] = debug ? debug_flag : NULL; argv[2] = NULL; - exec_wineserver( argv ); + while ((argv[0] = next_wineserver_path( &pathcopy ))) + execv( argv[0], argv ); fatal_error( "could not exec wineserver\n" ); } waitpid( pid, &status, 0 );
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/loader.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 883288960d6..87661cf9bde 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -30,6 +30,7 @@ #include <stdarg.h> #include <stdio.h> #include <signal.h> +#include <spawn.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> @@ -69,7 +70,6 @@ # include <mach/mach_error.h> # include <mach-o/getsect.h> # include <crt_externs.h> -# include <spawn.h> # ifndef _POSIX_SPAWN_DISABLE_ASLR # define _POSIX_SPAWN_DISABLE_ASLR 0x0100 # endif @@ -77,6 +77,7 @@ #ifdef __ANDROID__ # include <jni.h> #endif +extern char **environ;
#include "ntstatus.h" #define WIN32_NO_STATUS @@ -644,18 +645,23 @@ void start_server( BOOL debug )
if (!started) { - int status; + int status = 1; + pid_t pid; char *pathcopy = NULL; - int pid = fork(); - if (pid == -1) fatal_error( "fork: %s", strerror(errno) ); - if (!pid) + + argv[1] = debug ? debug_flag : NULL; + argv[2] = NULL; + + while ((argv[0] = next_wineserver_path( &pathcopy ))) { - argv[1] = debug ? debug_flag : NULL; - argv[2] = NULL; - while ((argv[0] = next_wineserver_path( &pathcopy ))) - execv( argv[0], argv ); - fatal_error( "could not exec wineserver\n" ); + status = posix_spawn( &pid, argv[0], NULL, NULL, argv, environ ); + free( argv[0] ); + if (!status) + break; } + free( pathcopy ); + if (status) fatal_error( "could not spawn wineserver\n" ); + waitpid( pid, &status, 0 ); status = WIFEXITED(status) ? WEXITSTATUS(status) : 1; if (status == 2) return; /* server lock held by someone else, will retry later */