Commit 9603ee07 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel: Show the exe name instead of wine-[kp]thread in ps and top.

parent 992a1af4
......@@ -7039,6 +7039,7 @@ done
for ac_header in \
IOKit/IOKitLib.h \
alsa/asoundlib.h \
......@@ -7118,6 +7119,7 @@ for ac_header in \
sys/mtio.h \
sys/param.h \
sys/poll.h \
sys/prctl.h \
sys/ptrace.h \
sys/reg.h \
sys/resource.h \
......@@ -14872,6 +14874,7 @@ fi
for ac_func in \
_lwp_create \
_lwp_self \
......@@ -14913,6 +14916,7 @@ for ac_func in \
mmap \
pclose \
popen \
prctl \
pread \
pwrite \
readlink \
......
......@@ -250,6 +250,7 @@ AC_CHECK_HEADERS(\
sys/mtio.h \
sys/param.h \
sys/poll.h \
sys/prctl.h \
sys/ptrace.h \
sys/reg.h \
sys/resource.h \
......@@ -1188,6 +1189,7 @@ AC_CHECK_FUNCS(\
mmap \
pclose \
popen \
prctl \
pread \
pwrite \
readlink \
......
......@@ -31,6 +31,9 @@
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif
#include <sys/types.h>
#include "ntstatus.h"
......@@ -837,6 +840,64 @@ static void start_process( void *arg )
/***********************************************************************
* set_process_name
*
* Change the process name in the ps output.
*/
static void set_process_name( int *argc, char *argv[], char *name )
{
#ifdef HAVE_PRCTL
int i, offset;
char *prctl_name = NULL;
char *end = argv[*argc-1] + strlen(argv[*argc-1]) + 1;
#ifndef PR_SET_NAME
# define PR_SET_NAME 15
#endif
if (!name)
{
char *p;
prctl_name = argv[1];
if ((p = strrchr( prctl_name, '\\' ))) prctl_name = p + 1;
if ((p = strrchr( prctl_name, '/' ))) prctl_name = p + 1;
}
else
{
if (strlen(name) <= strlen(argv[0])) prctl_name = name;
}
if (prctl_name && prctl( PR_SET_NAME, prctl_name ) != -1)
{
if (name)
{
strcpy( argv[0], name );
offset = argv[1] - (argv[0] + strlen(name) + 1);
}
else
{
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;
(*argc)--;
return;
}
#endif /* HAVE_PRCTL */
if (name) argv[0] = name;
else
{
/* remove argv[0] */
memmove( argv, argv + 1, *argc * sizeof(argv[0]) );
(*argc)--;
}
}
/***********************************************************************
* __wine_kernel_init
*
* Wine initialisation: load and start the main exe file.
......@@ -845,18 +906,17 @@ void __wine_kernel_init(void)
{
static const WCHAR dotW[] = {'.',0};
static const WCHAR exeW[] = {'.','e','x','e',0};
static char winevdm[] = "winevdm.exe";
WCHAR *p, main_exe_name[MAX_PATH];
HMODULE module;
DWORD type, error = 0;
PEB *peb = NtCurrentTeb()->Peb;
char *new_argv0 = NULL;
/* Initialize everything */
if (!process_init()) exit(1);
__wine_main_argv++; /* remove argv[0] (wine itself) */
__wine_main_argc--;
if (peb->ProcessParameters->ImagePathName.Buffer)
{
strcpyW( main_exe_name, peb->ProcessParameters->ImagePathName.Buffer );
......@@ -865,11 +925,11 @@ void __wine_kernel_init(void)
{
WCHAR exe_nameW[MAX_PATH];
MultiByteToWideChar( CP_UNIXCP, 0, __wine_main_argv[0], -1, exe_nameW, MAX_PATH );
MultiByteToWideChar( CP_UNIXCP, 0, __wine_main_argv[1], -1, exe_nameW, MAX_PATH );
if (!SearchPathW( NULL, exe_nameW, exeW, MAX_PATH, main_exe_name, NULL ) &&
!get_builtin_path( exe_nameW, exeW, main_exe_name, MAX_PATH ))
{
MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[1] );
ExitProcess( GetLastError() );
}
}
......@@ -879,7 +939,7 @@ void __wine_kernel_init(void)
if (!p || strchrW( p, '/' ) || strchrW( p, '\\' )) strcatW( main_exe_name, dotW );
TRACE( "starting process name=%s argv[0]=%s\n",
debugstr_w(main_exe_name), debugstr_a(__wine_main_argv[0]) );
debugstr_w(main_exe_name), debugstr_a(__wine_main_argv[1]) );
RtlInitUnicodeString( &NtCurrentTeb()->Peb->ProcessParameters->DllPath,
MODULE_get_dll_load_path(main_exe_name) );
......@@ -893,9 +953,7 @@ void __wine_kernel_init(void)
if (type == SCS_WOW_BINARY || type == SCS_DOS_BINARY ||
type == SCS_OS216_BINARY || type == SCS_PIF_BINARY)
{
__wine_main_argv--;
__wine_main_argc++;
__wine_main_argv[0] = "winevdm.exe";
new_argv0 = winevdm;
module = LoadLibraryExW( winevdmW, 0, DONT_RESOLVE_DLL_REFERENCES );
}
}
......@@ -909,6 +967,8 @@ void __wine_kernel_init(void)
ExitProcess( error );
}
set_process_name( &__wine_main_argc, __wine_main_argv, new_argv0 );
peb->ImageBaseAddress = module;
/* build command line */
......
......@@ -482,6 +482,9 @@
/* Define if we can use ppdev.h for parallel port access */
#undef HAVE_PPDEV
/* Define to 1 if you have the `prctl' function. */
#undef HAVE_PRCTL
/* Define to 1 if you have the `pread' function. */
#undef HAVE_PREAD
......@@ -731,6 +734,9 @@
/* Define to 1 if you have the <sys/poll.h> header file. */
#undef HAVE_SYS_POLL_H
/* Define to 1 if you have the <sys/prctl.h> header file. */
#undef HAVE_SYS_PRCTL_H
/* Define to 1 if you have the <sys/ptrace.h> header file. */
#undef HAVE_SYS_PTRACE_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment