kernel32: Overhaul the handling of argv in set_process_name().

Sebastian Lackner sebastian at fds-team.de
Wed Jul 13 15:13:00 CDT 2016


On 13.07.2016 21:52, Ken Thomases wrote:
> On Jul 13, 2016, at 2:25 PM, Sebastian Lackner
> <sebastian at fds-team.de> wrote:
>> 
>> On 13.07.2016 20:20, Ken Thomases wrote:
>> 
>>> Moving the code to the bottom could be done, although it would
>>> mean two #ifdef HAVE_SETPROCTITLE blocks, one to set
>>> shift_strings and the other to actually make the call.  The
>>> reason is that the shifting has to happen before the call to
>>> setprogname() because it's documented to keep the pointer that's
>>> passed in.  We can't pass it (a substring of) argv[1] and then
>>> shift the strings.
>> 
>> I'm not sure if two #ifdefs is actually that bad, it probably
>> should depend on the operating system anyway.
> 
> By "it" you mean the decision to shift the strings?  Why should that
> depend on the OS?  What reliable way do we have to detect if the OS
> works that way other than the strings actually being contiguous?

Please correct me if I'm wrong, but to my knowledge, the "ugly" shift
string method which depends on the exact memory layout only makes sense
on Linux. On all other operating systems the cmdline is obtained in a
different way and it does not matter what is stored in the process.

> 
>> On systems where it doesn't make a difference (like FreeBSD, ...)
>> this step can always be safely skipped.
> 
> By "systems where it doesn't make a difference", you mean those that
> have setproctitle()?  By "this step" you mean shifting the strings?
> That's what my patch already does.
> 

What I mean is that checking the operating system might be better than
checking if specific functions are available. To explain it with some
pseudo code, I was thinking about something like this:

--- snip ---
#ifdef __linux__
     // shift_strings check

    if (shift_strings)
    {
         // ...
    }
    else
#endif
    {
        // fallback method
    }

#ifdef HAVE_SETPROCTITLE
    // ...
#endif
#ifdef HAVE_SETPROGNAME
    // ...
#endif
#ifdef HAVE_PRCTL
    // ...
#endif
--- snip ---

Regards,
Sebastian



More information about the wine-devel mailing list