diff --git a/configure b/configure index 82be6a47ece..792c258a586 100755 --- a/configure +++ b/configure @@ -7037,6 +7037,7 @@ done + for ac_header in \ @@ -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 \ @@ -14870,6 +14872,7 @@ fi + for ac_func in \ @@ -14913,6 +14916,7 @@ for ac_func in \ mmap \ pclose \ popen \ + prctl \ pread \ pwrite \ readlink \ diff --git a/configure.ac b/configure.ac index 49ae20c44a1..98c799bf9ec 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index 5b5842da316..2cdc0efb666 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -31,6 +31,9 @@ #ifdef HAVE_SYS_TIME_H # include #endif +#ifdef HAVE_SYS_PRCTL_H +# include +#endif #include #include "ntstatus.h" @@ -836,6 +839,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 * @@ -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 */ diff --git a/include/config.h.in b/include/config.h.in index dd3dd6ffbb4..590e2c77272 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -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 header file. */ #undef HAVE_SYS_POLL_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PRCTL_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PTRACE_H