[PATCH v2] kernel32: Use setprogname(3) to set the program name if available.
Theodore Dubois
tblodt at icloud.com
Wed Apr 6 15:43:34 CDT 2016
I got the CC wrong on the email. Sorry for the wine-patches noise.
~Theodore
> On Apr 6, 2016, at 1:41 PM, Theodore Dubois <tblodt at icloud.com> wrote:
>
> This patch causes a segfault in the event that __wine_main_argv is not the argv that got passed to main. This happened in a program I wrote that acts as a custom wine loader. It creates an argv by using malloc, then passes that to wine_init.
>
> Why wouldn’t setprogname(argv[1]) be adequate?
>
> ~Theodore
>
>> On Feb 19, 2016, at 2:33 PM, Charles Davis <cdavis5x at gmail.com> wrote:
>>
>> Signed-off-by: Charles Davis <cdavis5x at gmail.com>
>> ---
>> Try 2:
>> * Clean up the #ifdefs a bit. (I'm not happy about the duplicated code, though.)
>> * Don't copy the progname into a static array. There's no need; the argument vector lasts as long as the process itself. (I suppose I was being overly defensive with that.)
>>
>> configure.ac | 1 +
>> dlls/kernel32/process.c | 17 ++++++++++++++---
>> 2 files changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index c9445e7..2ebbb10 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -2026,6 +2026,7 @@ AC_CHECK_FUNCS(\
>> sched_yield \
>> select \
>> setproctitle \
>> + setprogname \
>> setrlimit \
>> settimeofday \
>> sigaltstack \
>> diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
>> index 86333be..4771108 100644
>> --- a/dlls/kernel32/process.c
>> +++ b/dlls/kernel32/process.c
>> @@ -1118,9 +1118,20 @@ static void set_process_name( int argc, char *argv[] )
>> {
>> #ifdef HAVE_SETPROCTITLE
>> setproctitle("-%s", argv[1]);
>> -#endif
>> + /* remove argv[0] */
>> + memmove( argv, argv + 1, argc * sizeof(argv[0]) );
>> +#elif defined(HAVE_SETPROGNAME)
>> + int i, offset;
>> + char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
>>
>> -#ifdef HAVE_PRCTL
>> + offset = argv[1] - argv[0];
>> + memmove( argv[1] - offset, argv[1], end - argv[1] );
>> + memset( end - offset, 0, offset );
>> + for (i = 1; i < argc; i++) argv[i-1] = argv[i] - offset;
>> + argv[i-1] = NULL;
>> +
>> + setprogname( argv[0] );
>> +#elif defined(HAVE_PRCTL)
>> int i, offset;
>> char *p, *prctl_name = argv[1];
>> char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
>> @@ -1141,11 +1152,11 @@ static void set_process_name( int argc, char *argv[] )
>> argv[i-1] = NULL;
>> }
>> else
>> -#endif /* HAVE_PRCTL */
>> {
>> /* remove argv[0] */
>> memmove( argv, argv + 1, argc * sizeof(argv[0]) );
>> }
>> +#endif /* HAVE_PRCTL */
>> }
>>
>>
>> --
>> 2.7.1
>>
>>
>>
>
More information about the wine-devel
mailing list