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

Ken Thomases ken at codeweavers.com
Wed Jul 13 17:46:02 CDT 2016


On Jul 13, 2016, at 3:13 PM, Sebastian Lackner <sebastian at fds-team.de> wrote:
> 
> 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.

That's what I thought at first, too, but no.  Shifting the strings is what affects the output of ps on macOS, too.  The call to setprogname() affects some other process metadata query APIs (e.g. libproc), but I'm not aware of built-in commands which demonstrate their output.

The setproctitle() docs I've found online suggest that modifying argv (at least, argv[0]) works on FreeBSD, too.  It's just that setproctitle() is preferred.
<https://www.freebsd.org/cgi/man.cgi?query=setproctitle&sektion=3>

-Ken




More information about the wine-devel mailing list