Daniel Berger
2009-Sep-02 10:55 UTC
[Win32utils-devel] Question on CreateProcess and handle inheritance
Hi, I just wanted to make sure that I''m not confused by Michael Buselli''s comment and patch. As far as I can tell, if you set the bInheritHandle in the SECURITY_ATTRIBUTES structure that''s passed to CreateProcess to true, it''s the same as calling SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) after the fact. CreateProcess: lpProcessAttributes [in, optional] A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle to the new process object can be inherited by child processes. If lpProcessAttributes is NULL, the handle cannot be inherited. SetHandleInformation: HANDLE_FLAG_INHERIT If this flag is set, a child process created with the bInheritHandles parameter of CreateProcess set to TRUE will inherit the object handle. Or is this a case of "can" (i.e. it''s possible for the child to inherit the handle) vs "will" (i.e. the child process will definitely inherit the handle)? Regards, Dan
Heesob Park
2009-Sep-02 14:28 UTC
[Win32utils-devel] Question on CreateProcess and handle inheritance
Hi, 2009/9/2 Daniel Berger <djberg96 at gmail.com>:> Hi, > > I just wanted to make sure that I''m not confused by Michael Buselli''s > comment and patch. As far as I can tell, if you set the bInheritHandle > in the SECURITY_ATTRIBUTES structure that''s passed to CreateProcess to > true, it''s the same as calling SetHandleInformation(handle, > HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) after the fact. > > CreateProcess: > > lpProcessAttributes [in, optional] > > ? ?A pointer to a SECURITY_ATTRIBUTES structure that determines > whether the returned handle to the new process object can be inherited > by child processes. If lpProcessAttributes is NULL, the handle cannot > be inherited. >You must notice that "the returned handle" has nothing to do with the handle of stdin, stdout, or stderr. The SECURITY_ATTRIBUTES structure provides security settings for objects created by various functions, such as CreateFile, CreatePipe, CreateProcess, RegCreateKeyEx, or RegSaveKeyEx. The returned handle can be a file handle, process handle or registry handle.> SetHandleInformation: > > HANDLE_FLAG_INHERIT > > ? If this flag is set, a child process created with the > bInheritHandles parameter of CreateProcess set to TRUE will inherit > the object handle. > > Or is this a case of "can" (i.e. it''s possible for the child to > inherit the handle) vs "will" (i.e. the child process will definitely > inherit the handle)? >I guess the child process will definitely inherit the handle when bInheritHandles flag is set and the handle was not set by SetHandleInformation(handle,HANDLE_FLAG_INHERIT, 0). I think Michael Buselli''s patch is acceptable. Regards, Park Heesob
Seemingly Similar Threads
- clang-format sets executable permission on windows (openNativeFile ignores mode on Windows)
- problem usrmgr Version 3.2.4
- clang-format sets executable permission on windows (openNativeFile ignores mode on Windows)
- clang-format sets executable permission on windows (openNativeFile ignores mode on Windows)
- RE: Converting to 1.1.4, help please!