Skip to content

Commit f592858

Browse files
committed
Minor fixes
1 parent 79242f9 commit f592858

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/util/piped_process.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
// access from the same session token/permissions. This SHOULD be sufficient
3636
// for what we need.
3737
//
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
4040
// string "The Jabberwocky" from the example above before waiting for the ping
4141
// command to terminate. This reading can be done with any of the usual pipe
4242
// read/peek functions, so we use those.
@@ -66,7 +66,7 @@
6666
// finished, again undoing the interactive behaviour desired.
6767
// Since none of the above work effectivley, the chosen approach is to use a
6868
// 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
7070
// writing this has not been made smart, just a first choice option for how
7171
// frequently to poll.
7272
//
@@ -106,8 +106,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
106106
# ifdef _WIN32
107107
// Security attributes for pipe creation
108108
SECURITY_ATTRIBUTES sec_attr;
109-
// Ensure pipes are inherited
110109
sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
110+
// Ensure pipes are inherited
111111
sec_attr.bInheritHandle = TRUE;
112112
// This sets the security to the default for the current session access token
113113
// See following link for details
@@ -118,9 +118,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
118118
std::string base_name = "\\\\.\\pipe\\cbmc\\SMT2\\child\\";
119119
// Use process ID as a unique ID for this process at this time.
120120
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();
124123
child_std_IN_Rd = CreateNamedPipe(
125124
tmp_str,
126125
PIPE_ACCESS_INBOUND, // Reading for us
@@ -152,9 +151,8 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
152151
throw std::runtime_error(
153152
"Input pipe creation failed on SetHandleInformation");
154153
}
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();
158156
child_std_OUT_Rd = CreateNamedPipe(
159157
tmp_str,
160158
PIPE_ACCESS_INBOUND, // Reading for us
@@ -189,7 +187,6 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
189187
}
190188
// Create the child process
191189
STARTUPINFOW start_info;
192-
BOOL success = FALSE;
193190
ZeroMemory(&proc_info, sizeof(PROCESS_INFORMATION));
194191
ZeroMemory(&start_info, sizeof(STARTUPINFOW));
195192
start_info.cb = sizeof(STARTUPINFOW);
@@ -206,7 +203,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
206203
}
207204
// Note that we do NOT free this since it becomes part of the child
208205
// and causes heap corruption in Windows if we free!
209-
success = CreateProcessW(
206+
const BOOL success = CreateProcessW(
210207
NULL, // application name, we only use the command below
211208
_wcsdup(cmdline.c_str()), // command line
212209
NULL, // process security attributes
@@ -368,7 +365,9 @@ std::string piped_processt::receive()
368365
success = ReadFile(child_std_OUT_Rd, buff, BUFSIZE, &nbytes, NULL);
369366
#else
370367
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;
372371
#endif
373372
INVARIANT(
374373
nbytes < BUFSIZE,

0 commit comments

Comments
 (0)