79
79
# include " run.h" // for Windows arg quoting
80
80
# include " unicode.h" // for widen function
81
81
# include < tchar.h> // library for _tcscpy function
82
+ # include < util/make_unique.h>
83
+ # include < windows.h>
82
84
#else
83
85
# include < fcntl.h> // library for fcntl function
84
86
# include < poll.h> // library for poll function
@@ -185,7 +187,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
185
187
}
186
188
// Create the child process
187
189
STARTUPINFOW start_info;
188
- ZeroMemory (&proc_info, sizeof (PROCESS_INFORMATION));
190
+ proc_info = util_make_unique<PROCESS_INFORMATION>();
191
+ ZeroMemory (proc_info.get (), sizeof (PROCESS_INFORMATION));
189
192
ZeroMemory (&start_info, sizeof (STARTUPINFOW));
190
193
start_info.cb = sizeof (STARTUPINFOW);
191
194
start_info.hStdError = child_std_OUT_Wr;
@@ -211,7 +214,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
211
214
NULL , // use parent's environment
212
215
NULL , // use parent's current directory
213
216
&start_info, // STARTUPINFO pointer
214
- & proc_info); // receives PROCESS_INFORMATION
217
+ proc_info. get ()); // receives PROCESS_INFORMATION
215
218
// Close handles to the stdin and stdout pipes no longer needed by the
216
219
// child process. If they are not explicitly closed, there is no way to
217
220
// recognize that the child process has ended (but maybe we don't care).
@@ -298,7 +301,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
298
301
piped_processt::~piped_processt ()
299
302
{
300
303
# ifdef _WIN32
301
- TerminateProcess (proc_info. hProcess , 0 );
304
+ TerminateProcess (proc_info-> hProcess , 0 );
302
305
// Disconnecting the pipes also kicks the client off, it should be killed
303
306
// by now, but this will also force the client off.
304
307
// Note that pipes are cleaned up by Windows when all handles to the pipe
@@ -307,8 +310,8 @@ piped_processt::~piped_processt()
307
310
DisconnectNamedPipe (child_std_IN_Wr);
308
311
CloseHandle (child_std_OUT_Rd);
309
312
CloseHandle (child_std_IN_Wr);
310
- CloseHandle (proc_info. hProcess );
311
- CloseHandle (proc_info. hThread );
313
+ CloseHandle (proc_info-> hProcess );
314
+ CloseHandle (proc_info-> hThread );
312
315
# else
313
316
// Close the parent side of the remaining pipes
314
317
fclose (command_stream);
@@ -363,6 +366,8 @@ std::string piped_processt::receive()
363
366
success = ReadFile (child_std_OUT_Rd, buff, BUFSIZE, &nbytes, NULL );
364
367
#else
365
368
nbytes = read (pipe_output[0 ], buff, BUFSIZE);
369
+ // Added the status back in here to keep parity with old implementation
370
+ // TODO: check which statuses are really used/needed.
366
371
if (nbytes == 0 ) // Update if the pipe is stopped
367
372
process_state = statet::STOPPED;
368
373
success = nbytes > 0 ;
0 commit comments