Commit 9dffd134 authored by Alexandre Julliard's avatar Alexandre Julliard

libwine: Try the current load path in priority before the

WINELOADER/WINESERVER environment variables in wine_exec_wine_binary.
parent 767ad69a
...@@ -1481,14 +1481,8 @@ static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPW ...@@ -1481,14 +1481,8 @@ static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPW
if (winedebug) putenv( winedebug ); if (winedebug) putenv( winedebug );
if (unixdir) chdir(unixdir); if (unixdir) chdir(unixdir);
if (argv) if (argv) wine_exec_wine_binary( NULL, argv, getenv("WINELOADER") );
{
/* first, try for a WINELOADER environment variable */
const char *loader = getenv("WINELOADER");
if (loader) wine_exec_wine_binary( loader, argv, NULL, TRUE );
/* now use the standard search strategy */
wine_exec_wine_binary( NULL, argv, NULL, TRUE );
}
err = errno; err = errno;
write( execfd[1], &err, sizeof(err) ); write( execfd[1], &err, sizeof(err) );
_exit(1); _exit(1);
......
...@@ -589,7 +589,6 @@ void wine_server_release_fd( obj_handle_t handle, int unix_fd ) ...@@ -589,7 +589,6 @@ void wine_server_release_fd( obj_handle_t handle, int unix_fd )
static void start_server( const char *oldcwd ) static void start_server( const char *oldcwd )
{ {
static int started; /* we only try once */ static int started; /* we only try once */
char *path, *p;
char *argv[3]; char *argv[3];
if (!started) if (!started)
...@@ -602,22 +601,7 @@ static void start_server( const char *oldcwd ) ...@@ -602,22 +601,7 @@ static void start_server( const char *oldcwd )
argv[0] = "wineserver"; argv[0] = "wineserver";
argv[1] = TRACE_ON(server) ? "-d" : NULL; argv[1] = TRACE_ON(server) ? "-d" : NULL;
argv[2] = NULL; argv[2] = NULL;
/* if server is explicitly specified, use this */ wine_exec_wine_binary( argv[0], argv, getenv("WINESERVER") );
if ((p = getenv("WINESERVER")))
{
if (p[0] != '/' && oldcwd[0] == '/') /* make it an absolute path */
{
if (!(path = malloc( strlen(oldcwd) + strlen(p) + 1 )))
fatal_error( "out of memory\n" );
sprintf( path, "%s/%s", oldcwd, p );
p = path;
}
wine_exec_wine_binary( p, argv, NULL, FALSE );
fatal_perror( "could not exec the server '%s'\n"
" specified in the WINESERVER environment variable", p );
}
/* now use the standard search strategy */
wine_exec_wine_binary( argv[0], argv, NULL, FALSE );
fatal_error( "could not exec wineserver\n" ); fatal_error( "could not exec wineserver\n" );
} }
waitpid( pid, &status, 0 ); waitpid( pid, &status, 0 );
...@@ -809,7 +793,7 @@ static void create_config_dir(void) ...@@ -809,7 +793,7 @@ static void create_config_dir(void)
argv[3] = "--prefix"; argv[3] = "--prefix";
argv[4] = tmp_dir; argv[4] = tmp_dir;
argv[5] = NULL; argv[5] = NULL;
wine_exec_wine_binary( argv[0], (char **)argv, NULL, FALSE ); wine_exec_wine_binary( argv[0], (char **)argv, NULL );
rmdir( tmp_dir ); rmdir( tmp_dir );
fatal_perror( "could not exec wineprefixcreate" ); fatal_perror( "could not exec wineprefixcreate" );
} }
......
...@@ -33,7 +33,7 @@ extern const char *wine_get_config_dir(void); ...@@ -33,7 +33,7 @@ extern const char *wine_get_config_dir(void);
extern const char *wine_get_server_dir(void); extern const char *wine_get_server_dir(void);
extern const char *wine_get_user_name(void); extern const char *wine_get_user_name(void);
extern void wine_init_argv0_path( const char *argv0 ); extern void wine_init_argv0_path( const char *argv0 );
extern void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_preloader ); extern void wine_exec_wine_binary( const char *name, char **argv, const char *env_var );
/* dll loading */ /* dll loading */
......
...@@ -375,7 +375,7 @@ const char *wine_get_user_name(void) ...@@ -375,7 +375,7 @@ const char *wine_get_user_name(void)
} }
/* exec a binary using the preloader if requested; helper for wine_exec_wine_binary */ /* exec a binary using the preloader if requested; helper for wine_exec_wine_binary */
static void preloader_exec( char **argv, char **envp, int use_preloader ) static void preloader_exec( char **argv, int use_preloader )
{ {
#ifdef linux #ifdef linux
if (use_preloader) if (use_preloader)
...@@ -396,36 +396,40 @@ static void preloader_exec( char **argv, char **envp, int use_preloader ) ...@@ -396,36 +396,40 @@ static void preloader_exec( char **argv, char **envp, int use_preloader )
new_argv = xmalloc( (last_arg - argv + 2) * sizeof(*argv) ); new_argv = xmalloc( (last_arg - argv + 2) * sizeof(*argv) );
memcpy( new_argv + 1, argv, (last_arg - argv + 1) * sizeof(*argv) ); memcpy( new_argv + 1, argv, (last_arg - argv + 1) * sizeof(*argv) );
new_argv[0] = full_name; new_argv[0] = full_name;
if (envp) execve( full_name, new_argv, envp ); execv( full_name, new_argv );
else execv( full_name, new_argv );
free( new_argv ); free( new_argv );
free( full_name ); free( full_name );
return; return;
} }
#endif #endif
if (envp) execve( argv[0], argv, envp ); execv( argv[0], argv );
else execv( argv[0], argv );
} }
/* exec a wine internal binary (either the wine loader or the wine server) */ /* exec a wine internal binary (either the wine loader or the wine server) */
void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_preloader ) void wine_exec_wine_binary( const char *name, char **argv, const char *env_var )
{ {
static const char bindir[] = BINDIR; static const char bindir[] = BINDIR;
const char *path, *pos, *ptr; const char *path, *pos, *ptr;
int use_preloader = 0;
if (name && strchr( name, '/' )) if (!name) /* no name means default loader */
{ {
argv[0] = (char *)name; name = argv0_name;
preloader_exec( argv, envp, use_preloader ); use_preloader = 1;
return;
} }
else if (!name) name = argv0_name;
/* first, bin directory from the current libdir or argv0 */ /* first, bin directory from the current libdir or argv0 */
argv[0] = get_path_from_libdir( bindir, argv0_path, name ); argv[0] = get_path_from_libdir( bindir, argv0_path, name );
preloader_exec( argv, envp, use_preloader ); preloader_exec( argv, use_preloader );
free( argv[0] ); free( argv[0] );
/* then specified environment variable */
if (env_var)
{
argv[0] = (char *)env_var;
preloader_exec( argv, use_preloader );
}
/* now search in the Unix path */ /* now search in the Unix path */
if ((path = getenv( "PATH" ))) if ((path = getenv( "PATH" )))
{ {
...@@ -439,7 +443,7 @@ void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_ ...@@ -439,7 +443,7 @@ void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_
memcpy( argv[0], pos, ptr - pos ); memcpy( argv[0], pos, ptr - pos );
strcpy( argv[0] + (ptr - pos), "/" ); strcpy( argv[0] + (ptr - pos), "/" );
strcat( argv[0] + (ptr - pos), name ); strcat( argv[0] + (ptr - pos), name );
preloader_exec( argv, envp, use_preloader ); preloader_exec( argv, use_preloader );
pos = ptr; pos = ptr;
} }
free( argv[0] ); free( argv[0] );
...@@ -450,5 +454,5 @@ void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_ ...@@ -450,5 +454,5 @@ void wine_exec_wine_binary( const char *name, char **argv, char **envp, int use_
strcpy( argv[0], bindir ); strcpy( argv[0], bindir );
strcat( argv[0], "/" ); strcat( argv[0], "/" );
strcat( argv[0], name ); strcat( argv[0], name );
preloader_exec( argv, envp, use_preloader ); preloader_exec( argv, use_preloader );
} }
...@@ -67,6 +67,19 @@ static const char *get_threading(void) ...@@ -67,6 +67,19 @@ static const char *get_threading(void)
return ret ? "wine-pthread" : "wine-kthread"; return ret ? "wine-pthread" : "wine-kthread";
} }
/* build a new full path from the specified path and name */
static const char *build_new_path( const char *path, const char *name )
{
const char *p;
char *ret;
if (!(p = strrchr( path, '/' ))) return name;
p++;
ret = xmalloc( (p - path) + strlen(name) + 1 );
memcpy( ret, path, p - path );
strcpy( ret + (p - path), name );
return ret;
}
/********************************************************************** /**********************************************************************
* main * main
...@@ -75,31 +88,22 @@ int main( int argc, char *argv[] ) ...@@ -75,31 +88,22 @@ int main( int argc, char *argv[] )
{ {
const char *loader = getenv( "WINELOADER" ); const char *loader = getenv( "WINELOADER" );
const char *threads = get_threading(); const char *threads = get_threading();
const char *new_argv0 = build_new_path( argv[0], threads );
wine_init_argv0_path( new_argv0 );
if (loader) if (loader)
{ {
const char *path;
char *new_name, *new_loader;
if ((path = strrchr( loader, '/' ))) path++;
else path = loader;
new_name = xmalloc( (path - loader) + strlen(threads) + 1 );
memcpy( new_name, loader, path - loader );
strcpy( new_name + (path - loader), threads );
/* update WINELOADER with the new name */ /* update WINELOADER with the new name */
new_loader = xmalloc( sizeof("WINELOADER=") + strlen(new_name) ); const char *new_name = build_new_path( loader, threads );
char *new_loader = xmalloc( sizeof("WINELOADER=") + strlen(new_name) );
strcpy( new_loader, "WINELOADER=" ); strcpy( new_loader, "WINELOADER=" );
strcat( new_loader, new_name ); strcat( new_loader, new_name );
putenv( new_loader ); putenv( new_loader );
wine_exec_wine_binary( new_name, argv, NULL, TRUE ); loader = new_name;
} }
else
{ wine_exec_wine_binary( NULL, argv, loader );
wine_init_argv0_path( argv[0] ); fprintf( stderr, "wine: could not exec %s\n", threads );
wine_exec_wine_binary( threads, argv, NULL, TRUE );
}
fprintf( stderr, "wine: could not exec %s\n", argv[0] );
exit(1); exit(1);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment