mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-18 23:12:15 +08:00
Evaluate /proc/$PID/{root,cwd,cmdline} for native processes
* pinfo.cc (_pinfo::root): Fake default root for native processes. (open_commune_proc_parms): New helper function to access process parameter block. (_pinfo::cwd): Fetch missing cwd for native processes from processes parameter block. (_pinfo::cmdline): Ditto for command line. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
79511853f7
commit
575ec00a43
@ -1,3 +1,12 @@
|
|||||||
|
2015-06-08 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* pinfo.cc (_pinfo::root): Fake default root for native processes.
|
||||||
|
(open_commune_proc_parms): New helper function to access process
|
||||||
|
parameter block.
|
||||||
|
(_pinfo::cwd): Fetch missing cwd for native processes from processes
|
||||||
|
parameter block.
|
||||||
|
(_pinfo::cmdline): Ditto for command line.
|
||||||
|
|
||||||
2015-06-08 Corinna Vinschen <corinna@vinschen.de>
|
2015-06-08 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* pinfo.cc (_pinfo::commune_request): Don't try to send commune
|
* pinfo.cc (_pinfo::commune_request): Don't try to send commune
|
||||||
|
@ -850,7 +850,7 @@ _pinfo::root (size_t& n)
|
|||||||
char *s;
|
char *s;
|
||||||
if (!this || !pid)
|
if (!this || !pid)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (pid != myself->pid)
|
if (pid != myself->pid && !ISSTATE (this, PID_NOTCYGWIN))
|
||||||
{
|
{
|
||||||
commune_result cr = commune_request (PICOM_ROOT);
|
commune_result cr = commune_request (PICOM_ROOT);
|
||||||
s = cr.s;
|
s = cr.s;
|
||||||
@ -867,13 +867,60 @@ _pinfo::root (size_t& n)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HANDLE
|
||||||
|
open_commune_proc_parms (DWORD pid, PRTL_USER_PROCESS_PARAMETERS prupp)
|
||||||
|
{
|
||||||
|
HANDLE proc;
|
||||||
|
NTSTATUS status;
|
||||||
|
PROCESS_BASIC_INFORMATION pbi;
|
||||||
|
PEB lpeb;
|
||||||
|
|
||||||
|
proc = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
|
||||||
|
if (!proc)
|
||||||
|
return NULL;
|
||||||
|
status = NtQueryInformationProcess (proc, ProcessBasicInformation,
|
||||||
|
&pbi, sizeof pbi, NULL);
|
||||||
|
if (NT_SUCCESS (status)
|
||||||
|
&& ReadProcessMemory (proc, pbi.PebBaseAddress, &lpeb, sizeof lpeb, NULL)
|
||||||
|
&& ReadProcessMemory (proc, lpeb.ProcessParameters, prupp, sizeof *prupp,
|
||||||
|
NULL))
|
||||||
|
return proc;
|
||||||
|
NtClose (proc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
_pinfo::cwd (size_t& n)
|
_pinfo::cwd (size_t& n)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
if (!this || !pid)
|
if (!this || !pid)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (pid != myself->pid)
|
if (ISSTATE (this, PID_NOTCYGWIN))
|
||||||
|
{
|
||||||
|
RTL_USER_PROCESS_PARAMETERS rupp;
|
||||||
|
HANDLE proc = open_commune_proc_parms (dwProcessId, &rupp);
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
if (!proc)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tmp_pathbuf tp;
|
||||||
|
PWCHAR cwd = tp.w_get ();
|
||||||
|
|
||||||
|
if (ReadProcessMemory (proc, rupp.CurrentDirectoryName.Buffer,
|
||||||
|
cwd, rupp.CurrentDirectoryName.Length,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
/* Drop trailing backslash, add trailing \0 in passing. */
|
||||||
|
cwd[rupp.CurrentDirectoryName.Length / sizeof (WCHAR) - 1]
|
||||||
|
= L'\0';
|
||||||
|
s = (char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH);
|
||||||
|
mount_table->conv_to_posix_path (cwd, s, 0);
|
||||||
|
n = strlen (s) + 1;
|
||||||
|
}
|
||||||
|
NtClose (proc);
|
||||||
|
}
|
||||||
|
else if (pid != myself->pid)
|
||||||
{
|
{
|
||||||
commune_result cr = commune_request (PICOM_CWD);
|
commune_result cr = commune_request (PICOM_CWD);
|
||||||
s = cr.s;
|
s = cr.s;
|
||||||
@ -894,7 +941,38 @@ _pinfo::cmdline (size_t& n)
|
|||||||
char *s;
|
char *s;
|
||||||
if (!this || !pid)
|
if (!this || !pid)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (pid != myself->pid)
|
if (ISSTATE (this, PID_NOTCYGWIN))
|
||||||
|
{
|
||||||
|
RTL_USER_PROCESS_PARAMETERS rupp;
|
||||||
|
HANDLE proc = open_commune_proc_parms (dwProcessId, &rupp);
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
if (!proc)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tmp_pathbuf tp;
|
||||||
|
PWCHAR cmdline = tp.w_get ();
|
||||||
|
|
||||||
|
if (ReadProcessMemory (proc, rupp.CommandLine.Buffer, cmdline,
|
||||||
|
rupp.CommandLine.Length, NULL))
|
||||||
|
{
|
||||||
|
/* Add trailing \0. */
|
||||||
|
cmdline[rupp.CommandLine.Length / sizeof (WCHAR)]
|
||||||
|
= L'\0';
|
||||||
|
n = sys_wcstombs_alloc (&s, HEAP_COMMUNE, cmdline,
|
||||||
|
rupp.CommandLine.Length
|
||||||
|
/ sizeof (WCHAR));
|
||||||
|
/* Quotes & Spaces post-processing. */
|
||||||
|
bool in_quote = false;
|
||||||
|
for (char *c = s; *c; ++c)
|
||||||
|
if (*c == '"')
|
||||||
|
in_quote = !in_quote;
|
||||||
|
else if (*c == ' ' && !in_quote)
|
||||||
|
*c = '\0';
|
||||||
|
}
|
||||||
|
NtClose (proc);
|
||||||
|
}
|
||||||
|
else if (pid != myself->pid)
|
||||||
{
|
{
|
||||||
commune_result cr = commune_request (PICOM_CMDLINE);
|
commune_result cr = commune_request (PICOM_CMDLINE);
|
||||||
s = cr.s;
|
s = cr.s;
|
||||||
|
@ -12,3 +12,7 @@ Bug Fixes
|
|||||||
|
|
||||||
- Fix installing newly added bind mounts with `mount -a'.
|
- Fix installing newly added bind mounts with `mount -a'.
|
||||||
Addresses: https://cygwin.com/ml/cygwin/2015-06/msg00150.html
|
Addresses: https://cygwin.com/ml/cygwin/2015-06/msg00150.html
|
||||||
|
|
||||||
|
- Add missing evaluation of /proc/$PID/{root,cwd,cmdline} for native processes.
|
||||||
|
Addresses: https://cygwin.com/ml/cygwin/2015-06/msg00173.html
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user