CreateProcess + STARTF_USESTDHANDLES

Oleg Prokhorov xolegpro at rbcmail.ru
Sun Feb 23 11:18:43 CST 2003


Hello ,

  This bug occurs to chess.net client application and may be some others.

  I've debugged a problem with CreateProcess where parent process
  overrides child process' stdin, stderr, stdout handles.

  It can be done like this (portion of a code)

// Override
   siStartInfo.dwFlags = STARTF_USESTDHANDLES;

// Create the child process.
 
   if (!CreateProcess("child.exe", 
      "child.exe",       // command line 
      NULL,          // process security attributes 
      NULL,          // primary thread security attributes 
      TRUE,          // handles are inherited 
DETACHED_PROCESS, // creation flags
      NULL,          // use parent's environment 
      NULL,          // use parent's current directory 
      &siStartInfo,  // STARTUPINFO pointer 
      &piProcInfo))  // receives PROCESS_INFORMATION 
   ErrorExit("Create process failed"); 


  The bug in Wine is the following lines of scheduler/process.c

    else if (!(main_create_flags & (DETACHED_PROCESS|CREATE_NEW_CONSOLE)))
    {
        SetStdHandle( STD_INPUT_HANDLE,  current_startupinfo.hStdInput  );
        SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
        SetStdHandle( STD_ERROR_HANDLE,  current_startupinfo.hStdError  );
    }

  You see it does not allow any std handles overriding if
  main_create_flags' DETACHED_PROCESS or CREATE_NEW_CONSOLE bit is
  set on, which is partially wrong in Windows.
  Cause it doesn't take in account siStartInfo.dwFlags=STARTF_USESTDHANDLES,
  which requires overriding.

  The full proof of a bug is included, test it on Windows. It may be
  used as on of wine tests, if you need that.

  The bug seems to be easy to fix but to the wine server / client process
  creation insider.

  I'm not sure what will be better to you fix it yourself, or guide me
  how to do it in the most proper way.
  
-- 
Best regards,
 Oleg                          mailto:xolegpro at rbcmail.ru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: child.c
Type: application/octet-stream
Size: 769 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20030223/d556f4b8/child.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parent.c
Type: application/octet-stream
Size: 4362 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20030223/d556f4b8/parent.obj


More information about the wine-devel mailing list