35
35
// access from the same session token/permissions. This SHOULD be sufficient
36
36
// for what we need.
37
37
//
38
- // Non-blocking pipes allow immediate reading of any data on the pipre which
39
- // matches the Linux/MasOC pipe behvariour and also allows reading of the
38
+ // Non-blocking pipes allow immediate reading of any data on the pipe which
39
+ // matches the Linux/MacOS pipe behaviour and also allows reading of the
40
40
// string "The Jabberwocky" from the example above before waiting for the ping
41
41
// command to terminate. This reading can be done with any of the usual pipe
42
42
// read/peek functions, so we use those.
66
66
// finished, again undoing the interactive behaviour desired.
67
67
// Since none of the above work effectivley, the chosen approach is to use a
68
68
// non-blocking peek to see if there is anthing to read, and use a sleep and
69
- // poll behaviour that might be puch busier than we want. At the time of
69
+ // poll behaviour that might be much busier than we want. At the time of
70
70
// writing this has not been made smart, just a first choice option for how
71
71
// frequently to poll.
72
72
//
@@ -106,8 +106,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
106
106
# ifdef _WIN32
107
107
// Security attributes for pipe creation
108
108
SECURITY_ATTRIBUTES sec_attr;
109
- // Ensure pipes are inherited
110
109
sec_attr.nLength = sizeof (SECURITY_ATTRIBUTES);
110
+ // Ensure pipes are inherited
111
111
sec_attr.bInheritHandle = TRUE ;
112
112
// This sets the security to the default for the current session access token
113
113
// See following link for details
@@ -118,9 +118,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
118
118
std::string base_name = " \\\\ .\\ pipe\\ cbmc\\ SMT2\\ child\\ " ;
119
119
// Use process ID as a unique ID for this process at this time.
120
120
base_name.append (std::to_string (GetCurrentProcessId ()));
121
- std::string tmp_name = base_name;
122
- tmp_name.append (" \\ IN" );
123
- LPCSTR tmp_str = tmp_name.c_str ();
121
+ const std::string in_name = base_name + " \\ IN" ;
122
+ LPCSTR tmp_str = in_name.c_str ();
124
123
child_std_IN_Rd = CreateNamedPipe (
125
124
tmp_str,
126
125
PIPE_ACCESS_INBOUND, // Reading for us
@@ -152,9 +151,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
152
151
throw std::runtime_error (
153
152
" Input pipe creation failed on SetHandleInformation" );
154
153
}
155
- tmp_name = base_name;
156
- tmp_name.append (" \\ OUT" );
157
- tmp_str = tmp_name.c_str ();
154
+ const std::string out_name = base_name + " \\ OUT" ;
155
+ tmp_str = out_name.c_str ();
158
156
child_std_OUT_Rd = CreateNamedPipe (
159
157
tmp_str,
160
158
PIPE_ACCESS_INBOUND, // Reading for us
@@ -189,7 +187,6 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
189
187
}
190
188
// Create the child process
191
189
STARTUPINFOW start_info;
192
- BOOL success = FALSE ;
193
190
ZeroMemory (&proc_info, sizeof (PROCESS_INFORMATION));
194
191
ZeroMemory (&start_info, sizeof (STARTUPINFOW));
195
192
start_info.cb = sizeof (STARTUPINFOW);
@@ -206,7 +203,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
206
203
}
207
204
// Note that we do NOT free this since it becomes part of the child
208
205
// and causes heap corruption in Windows if we free!
209
- success = CreateProcessW (
206
+ const BOOL success = CreateProcessW (
210
207
NULL , // application name, we only use the command below
211
208
_wcsdup (cmdline.c_str ()), // command line
212
209
NULL , // process security attributes
@@ -368,7 +365,9 @@ std::string piped_processt::receive()
368
365
success = ReadFile (child_std_OUT_Rd, buff, BUFSIZE, &nbytes, NULL );
369
366
#else
370
367
nbytes = read (pipe_output[0 ], buff, BUFSIZE);
371
- success = nbytes > 0 ; // 0 is error, -1 is nothing to read
368
+ if (nbytes == 0 ) // Update if the pipe is stopped
369
+ process_state = statet::STOPPED;
370
+ success = nbytes > 0 ;
372
371
#endif
373
372
INVARIANT (
374
373
nbytes < BUFSIZE,
0 commit comments