* shared.cc (get_shared_parent_dir): Use global shared_parent_dir
instead of local dir variable and create handle not inheritable to avoid accumulating stray handles in child processes. (get_session_parent_dir): Ditto with session_parent_dir variable.
This commit is contained in:
parent
6a8a9ad8d8
commit
c5785504f8
|
@ -1,3 +1,10 @@
|
||||||
|
2011-11-18 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* shared.cc (get_shared_parent_dir): Use global shared_parent_dir
|
||||||
|
instead of local dir variable and create handle not inheritable to
|
||||||
|
avoid accumulating stray handles in child processes.
|
||||||
|
(get_session_parent_dir): Ditto with session_parent_dir variable.
|
||||||
|
|
||||||
2011-11-17 Corinna Vinschen <corinna@vinschen.de>
|
2011-11-17 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* shared.cc (shared_info::create): Open global shared data section
|
* shared.cc (shared_info::create): Open global shared data section
|
||||||
|
|
|
@ -127,15 +127,16 @@ init_installation_root ()
|
||||||
/* This function returns a handle to the top-level directory in the global
|
/* This function returns a handle to the top-level directory in the global
|
||||||
NT namespace used to implement global objects including shared memory. */
|
NT namespace used to implement global objects including shared memory. */
|
||||||
|
|
||||||
|
static HANDLE NO_COPY shared_parent_dir;
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
get_shared_parent_dir ()
|
get_shared_parent_dir ()
|
||||||
{
|
{
|
||||||
static HANDLE dir;
|
|
||||||
UNICODE_STRING uname;
|
UNICODE_STRING uname;
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (!dir)
|
if (!shared_parent_dir)
|
||||||
{
|
{
|
||||||
WCHAR bnoname[MAX_PATH];
|
WCHAR bnoname[MAX_PATH];
|
||||||
__small_swprintf (bnoname, L"\\BaseNamedObjects\\%s%s-%S",
|
__small_swprintf (bnoname, L"\\BaseNamedObjects\\%s%s-%S",
|
||||||
|
@ -143,31 +144,33 @@ get_shared_parent_dir ()
|
||||||
_cygwin_testing ? cygwin_version.dll_build_date : "",
|
_cygwin_testing ? cygwin_version.dll_build_date : "",
|
||||||
&installation_key);
|
&installation_key);
|
||||||
RtlInitUnicodeString (&uname, bnoname);
|
RtlInitUnicodeString (&uname, bnoname);
|
||||||
InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF,
|
InitializeObjectAttributes (&attr, &uname, OBJ_OPENIF, NULL,
|
||||||
NULL, everyone_sd (CYG_SHARED_DIR_ACCESS));
|
everyone_sd (CYG_SHARED_DIR_ACCESS));
|
||||||
status = NtCreateDirectoryObject (&dir, CYG_SHARED_DIR_ACCESS, &attr);
|
status = NtCreateDirectoryObject (&shared_parent_dir,
|
||||||
|
CYG_SHARED_DIR_ACCESS, &attr);
|
||||||
if (!NT_SUCCESS (status))
|
if (!NT_SUCCESS (status))
|
||||||
api_fatal ("NtCreateDirectoryObject(%S): %p", &uname, status);
|
api_fatal ("NtCreateDirectoryObject(%S): %p", &uname, status);
|
||||||
}
|
}
|
||||||
return dir;
|
return shared_parent_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HANDLE NO_COPY session_parent_dir;
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
get_session_parent_dir ()
|
get_session_parent_dir ()
|
||||||
{
|
{
|
||||||
static HANDLE dir;
|
|
||||||
UNICODE_STRING uname;
|
UNICODE_STRING uname;
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (!dir)
|
if (!session_parent_dir)
|
||||||
{
|
{
|
||||||
PROCESS_SESSION_INFORMATION psi;
|
PROCESS_SESSION_INFORMATION psi;
|
||||||
status = NtQueryInformationProcess (NtCurrentProcess (),
|
status = NtQueryInformationProcess (NtCurrentProcess (),
|
||||||
ProcessSessionInformation,
|
ProcessSessionInformation,
|
||||||
&psi, sizeof psi, NULL);
|
&psi, sizeof psi, NULL);
|
||||||
if (!NT_SUCCESS (status) || psi.SessionId == 0)
|
if (!NT_SUCCESS (status) || psi.SessionId == 0)
|
||||||
dir = get_shared_parent_dir ();
|
session_parent_dir = get_shared_parent_dir ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WCHAR bnoname[MAX_PATH];
|
WCHAR bnoname[MAX_PATH];
|
||||||
|
@ -177,14 +180,15 @@ get_session_parent_dir ()
|
||||||
_cygwin_testing ? cygwin_version.dll_build_date : "",
|
_cygwin_testing ? cygwin_version.dll_build_date : "",
|
||||||
&installation_key);
|
&installation_key);
|
||||||
RtlInitUnicodeString (&uname, bnoname);
|
RtlInitUnicodeString (&uname, bnoname);
|
||||||
InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF,
|
InitializeObjectAttributes (&attr, &uname, OBJ_OPENIF, NULL,
|
||||||
NULL, everyone_sd(CYG_SHARED_DIR_ACCESS));
|
everyone_sd(CYG_SHARED_DIR_ACCESS));
|
||||||
status = NtCreateDirectoryObject (&dir, CYG_SHARED_DIR_ACCESS, &attr);
|
status = NtCreateDirectoryObject (&session_parent_dir,
|
||||||
|
CYG_SHARED_DIR_ACCESS, &attr);
|
||||||
if (!NT_SUCCESS (status))
|
if (!NT_SUCCESS (status))
|
||||||
api_fatal ("NtCreateDirectoryObject(%S): %p", &uname, status);
|
api_fatal ("NtCreateDirectoryObject(%S): %p", &uname, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dir;
|
return session_parent_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * __stdcall
|
char * __stdcall
|
||||||
|
|
Loading…
Reference in New Issue