Commit a3e0cfc5 authored by Alexandre Julliard's avatar Alexandre Julliard

Get full path of argv[0] before we change directories.

Make sure process names are long path names. Cleaned up initialisation a bit.
parent 56adb25f
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "windef.h" #include "windef.h"
extern BOOL MAIN_MainInit( char *argv[] ); extern BOOL MAIN_MainInit(void);
extern void MAIN_WineInit(void); extern void MAIN_WineInit(void);
extern int MAIN_GetLanguageID(char*lang, char*country, char*charset, char*dialect); extern int MAIN_GetLanguageID(char*lang, char*country, char*charset, char*dialect);
extern void MAIN_ParseDebugOptions(const char *options); extern void MAIN_ParseDebugOptions(const char *options);
......
...@@ -21,6 +21,7 @@ struct options ...@@ -21,6 +21,7 @@ struct options
extern struct options Options; extern struct options Options;
extern const char *argv0; extern const char *argv0;
extern const char *full_argv0;
extern void OPTIONS_Usage(void) WINE_NORETURN; extern void OPTIONS_Usage(void) WINE_NORETURN;
extern void OPTIONS_ParseOptions( char *argv[] ); extern void OPTIONS_ParseOptions( char *argv[] );
......
...@@ -147,7 +147,6 @@ extern DWORD WINAPI MapProcessHandle( HANDLE handle ); ...@@ -147,7 +147,6 @@ extern DWORD WINAPI MapProcessHandle( HANDLE handle );
extern BOOL ENV_BuildEnvironment(void); extern BOOL ENV_BuildEnvironment(void);
/* scheduler/process.c */ /* scheduler/process.c */
extern BOOL PROCESS_Init(void);
extern void PROCESS_InitWine( int argc, char *argv[] ) WINE_NORETURN; extern void PROCESS_InitWine( int argc, char *argv[] ) WINE_NORETURN;
extern void PROCESS_InitWinelib( int argc, char *argv[] ) WINE_NORETURN; extern void PROCESS_InitWinelib( int argc, char *argv[] ) WINE_NORETURN;
extern PDB *PROCESS_IdToPDB( DWORD id ); extern PDB *PROCESS_IdToPDB( DWORD id );
......
...@@ -432,7 +432,7 @@ BOOL MZ_InitTask( LPDOSTASK lpDosTask ) ...@@ -432,7 +432,7 @@ BOOL MZ_InitTask( LPDOSTASK lpDosTask )
/* now load dosmod */ /* now load dosmod */
/* check argv[0]-derived paths first, since the newest dosmod is most likely there /* check argv[0]-derived paths first, since the newest dosmod is most likely there
* (at least it was once for Andreas Mohr, so I decided to make it easier for him) */ * (at least it was once for Andreas Mohr, so I decided to make it easier for him) */
fpath=strrchr(strcpy(path,argv0),'/'); fpath=strrchr(strcpy(path,full_argv0),'/');
if (fpath) { if (fpath) {
strcpy(fpath,"/dosmod"); strcpy(fpath,"/dosmod");
execl(path,fname,farg,NULL); execl(path,fname,farg,NULL);
......
...@@ -27,16 +27,8 @@ DEFAULT_DEBUG_CHANNEL(server); ...@@ -27,16 +27,8 @@ DEFAULT_DEBUG_CHANNEL(server);
/*********************************************************************** /***********************************************************************
* Main initialisation routine * Main initialisation routine
*/ */
BOOL MAIN_MainInit( char *argv[] ) BOOL MAIN_MainInit(void)
{ {
/* store the program name */
argv0 = argv[0];
/* Create the initial process */
if (!PROCESS_Init()) return FALSE;
/* Parse command line arguments */
OPTIONS_ParseOptions( argv );
MAIN_WineInit(); MAIN_WineInit();
/* Load the configuration file */ /* Load the configuration file */
......
...@@ -40,7 +40,8 @@ struct options Options = ...@@ -40,7 +40,8 @@ struct options Options =
NULL /* Alternate config file name */ NULL /* Alternate config file name */
}; };
const char *argv0; const char *argv0; /* the original argv[0] */
const char *full_argv0; /* the full path of argv[0] (if known) */
static char *inherit_str; /* options to pass to child processes */ static char *inherit_str; /* options to pass to child processes */
......
...@@ -459,6 +459,20 @@ int CLIENT_InitServer(void) ...@@ -459,6 +459,20 @@ int CLIENT_InitServer(void)
break; break;
} }
/* if argv[0] is a relative path, make it absolute */
full_argv0 = argv0;
if (oldcwd && argv0[0] != '/' && strchr( argv0, '/' ))
{
char *new_argv0 = malloc( strlen(oldcwd) + strlen(argv0) + 2 );
if (new_argv0)
{
strcpy( new_argv0, oldcwd );
strcat( new_argv0, "/" );
strcat( new_argv0, argv0 );
full_argv0 = new_argv0;
}
}
/* get the server directory name */ /* get the server directory name */
if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" ); if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" );
configdir = get_config_dir(); configdir = get_config_dir();
......
...@@ -171,13 +171,18 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule ) ...@@ -171,13 +171,18 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
/*********************************************************************** /***********************************************************************
* PROCESS_Init * process_init
*
* Main process initialisation code
*/ */
BOOL PROCESS_Init(void) static BOOL process_init( char *argv[] )
{ {
struct init_process_request *req; struct init_process_request *req;
PDB *pdb = PROCESS_Current(); PDB *pdb = PROCESS_Current();
/* store the program name */
argv0 = argv[0];
/* Fill the initial process structure */ /* Fill the initial process structure */
pdb->exit_code = STILL_ACTIVE; pdb->exit_code = STILL_ACTIVE;
pdb->threads = 1; pdb->threads = 1;
...@@ -227,7 +232,10 @@ BOOL PROCESS_Init(void) ...@@ -227,7 +232,10 @@ BOOL PROCESS_Init(void)
/* Initialize syslevel handling */ /* Initialize syslevel handling */
SYSLEVEL_Init(); SYSLEVEL_Init();
return TRUE; /* Parse command line arguments */
OPTIONS_ParseOptions( argv );
return MAIN_MainInit();
} }
...@@ -396,8 +404,8 @@ static void PROCESS_Start( HMODULE main_module, LPSTR filename ) ...@@ -396,8 +404,8 @@ static void PROCESS_Start( HMODULE main_module, LPSTR filename )
{ {
/* if no explicit filename, use argv[0] */ /* if no explicit filename, use argv[0] */
if (!(filename = malloc( MAX_PATH ))) ExitProcess(1); if (!(filename = malloc( MAX_PATH ))) ExitProcess(1);
if (!GetFullPathNameA( argv0, MAX_PATH, filename, NULL )) if (!GetLongPathNameA( full_argv0, filename, MAX_PATH ))
lstrcpynA( filename, argv0, MAX_PATH ); lstrcpynA( filename, full_argv0, MAX_PATH );
} }
/* load main module */ /* load main module */
...@@ -432,7 +440,7 @@ void PROCESS_InitWine( int argc, char *argv[] ) ...@@ -432,7 +440,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
DWORD type; DWORD type;
/* Initialize everything */ /* Initialize everything */
if (!MAIN_MainInit( argv )) exit(1); if (!process_init( argv )) exit(1);
main_exe_argv = ++argv; /* remove argv[0] (wine itself) */ main_exe_argv = ++argv; /* remove argv[0] (wine itself) */
...@@ -519,7 +527,7 @@ void PROCESS_InitWinelib( int argc, char *argv[] ) ...@@ -519,7 +527,7 @@ void PROCESS_InitWinelib( int argc, char *argv[] )
{ {
HMODULE main_module; HMODULE main_module;
if (!MAIN_MainInit( argv )) exit(1); if (!process_init( argv )) exit(1);
/* create 32-bit module for main exe */ /* create 32-bit module for main exe */
if (!(main_module = BUILTIN32_LoadExeModule())) ExitProcess( GetLastError() ); if (!(main_module = BUILTIN32_LoadExeModule())) ExitProcess( GetLastError() );
...@@ -636,11 +644,11 @@ static void exec_wine_binary( char **argv, char **envp ) ...@@ -636,11 +644,11 @@ static void exec_wine_binary( char **argv, char **envp )
execve( argv[0], argv, envp ); execve( argv[0], argv, envp );
/* now try the path of argv0 of the current binary */ /* now try the path of argv0 of the current binary */
if (!(argv[0] = malloc( strlen(argv0) + 6 ))) return; if (!(argv[0] = malloc( strlen(full_argv0) + 6 ))) return;
if ((ptr = strrchr( argv0, '/' ))) if ((ptr = strrchr( full_argv0, '/' )))
{ {
memcpy( argv[0], argv0, ptr - argv0 ); memcpy( argv[0], full_argv0, ptr - full_argv0 );
strcpy( argv[0] + (ptr - argv0), "/wine" ); strcpy( argv[0] + (ptr - full_argv0), "/wine" );
execve( argv[0], argv, envp ); execve( argv[0], argv, envp );
} }
free( argv[0] ); free( argv[0] );
...@@ -781,7 +789,7 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env, ...@@ -781,7 +789,7 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
} }
else /* new wine process */ else /* new wine process */
{ {
if (!GetFullPathNameA( filename, server_remaining(req->filename), req->filename, NULL )) if (!GetLongPathNameA( filename, req->filename, server_remaining(req->filename) ))
lstrcpynA( req->filename, filename, server_remaining(req->filename) ); lstrcpynA( req->filename, filename, server_remaining(req->filename) );
} }
if (server_call( REQ_NEW_PROCESS )) return FALSE; if (server_call( REQ_NEW_PROCESS )) return FALSE;
......
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