KERNEL: force copying of DOS-style path into argv[0] of
PE process
Alexandre Julliard
julliard at winehq.org
Mon Oct 31 15:45:42 CST 2005
Alex Villacís Lasso <a_villacis at palosanto.com> writes:
> Alexandre Julliard wrote:
>
>>It's OK to change argv[0] when started from a Unix shell, but not when
>>started from another Windows process. Your patch does it in all cases,
>>which is not correct.
>>
> Sounds reasonable. What is the proper way to tell apart the two cases?
I would suggest something like this:
Index: dlls/kernel/process.c
===================================================================
RCS file: /opt/cvs-commit/wine/dlls/kernel/process.c,v
retrieving revision 1.109
diff -u -p -r1.109 process.c
--- dlls/kernel/process.c 10 Oct 2005 10:28:48 -0000 1.109
+++ dlls/kernel/process.c 31 Oct 2005 21:43:46 -0000
@@ -515,19 +515,23 @@ static void set_registry_environment(voi
*/
static void set_library_wargv( char **argv )
{
- int argc;
+ int argc, first = 0;
char *q;
WCHAR *p;
WCHAR **wargv;
DWORD total = 0;
- for (argc = 0; argv[argc]; argc++)
+ /* if we didn't get a command line from our parent,
+ * force argv[0] to be the path of the main binary */
+ if (argv[0] && !NtCurrentTeb()->Peb->ProcessParameters->CommandLine.Buffer) first = 1;
+
+ for (argc = first; argv[argc]; argc++)
total += MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, NULL, 0 );
wargv = RtlAllocateHeap( GetProcessHeap(), 0,
total * sizeof(WCHAR) + (argc + 1) * sizeof(*wargv) );
p = (WCHAR *)(wargv + argc + 1);
- for (argc = 0; argv[argc]; argc++)
+ for (argc = first; argv[argc]; argc++)
{
DWORD reslen = MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, p, total );
wargv[argc] = p;
@@ -535,6 +539,7 @@ static void set_library_wargv( char **ar
total -= reslen;
}
wargv[argc] = NULL;
+ if (first) wargv[0] = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
/* convert argv back from Unicode since it has to be in the Ansi codepage not the Unix one */
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list