kernel32: Overhaul the handling of argv in set_process_name().
commita73045d6a018f5b8012ef53f53d3ea7786da8a0a
authorKen Thomases <ken@codeweavers.com>
Tue, 12 Jul 2016 04:44:20 +0000 (11 23:44 -0500)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 15 Jul 2016 02:16:11 +0000 (15 11:16 +0900)
tree6a585ecd6d4c765e55697c0ccb76bf53c6a4ac08
parent789c4c45ce2731d1b886e52160bce032da0190b0
kernel32: Overhaul the handling of argv in set_process_name().

This fixes several problems with the code:

* The code had been assuming that the argument strings pointed to by the argv
  array are contiguous iff certain process-name-setting functions are available.
  This doesn't seem reliable.  Instead, test if it's true and shift the strings
  if so.

  However, setproctitle() is specifically documented as a preferred alternative
  to the technique of overwriting the arg strings, so don't shift the strings
  if that's available.

* Use the last path component, recognizing backslash as a path separator, for
  setprogname() in addition to prctl().  First, setprogname() is documented as
  searching for the last component itself, but it doesn't understand Windows-
  style paths, so we need to help it.  Second, on some platforms (e.g. macOS),
  setprogname(), like prctl(), has a fairly small internal length limit (e.g.
  32 characters).  So, concentrate on the most meaningful part of the path.

* Remove argv[0] from argv whether or not there are any process-name-setting
  functions available.  This is necessary for the proper functioning of Wine,
  so it must be done on all platforms.  This part of the logic was lost with
  commit 5a4576ee0.

* Call all available process-name-setting functions instead of treating them
  as mutually exclusive alternatives.  This is also logic that was lost with
  commit 5a4576ee0.

Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
dlls/kernel32/process.c