| 178 | } |
| 179 | |
| 180 | bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::string& filename) |
| 181 | { |
| 182 | std::size_t bytes_to_read; |
| 183 | ssize_t bytes_read; |
| 184 | |
| 185 | char type = 0; |
| 186 | bytes_to_read = sizeof(char); |
| 187 | bytes_read = read(rpipe, &type, bytes_to_read); |
| 188 | if (bytes_read <= 0) { |
| 189 | if (errno == EAGAIN) |
| 190 | return true; |
| 191 | |
| 192 | // TODO: log details about failure |
| 193 | |
| 194 | // need to increment so a missing pipe (i.e. premature exit of forked process) results in an error exitcode |
| 195 | ++result; |
| 196 | return false; |
| 197 | } |
| 198 | if (bytes_read != bytes_to_read) { |
| 199 | std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl; |
| 200 | std::exit(EXIT_FAILURE); |
| 201 | } |
| 202 | |
| 203 | if (type != PipeWriter::REPORT_OUT && |
| 204 | type != PipeWriter::REPORT_ERROR && |
| 205 | type != PipeWriter::REPORT_SUPPR_INLINE && |
| 206 | type != PipeWriter::REPORT_SUPPR && |
| 207 | type != PipeWriter::CHILD_END && |
| 208 | type != PipeWriter::REPORT_METRIC && |
| 209 | type != PipeWriter::REPORT_TIMER) { |
| 210 | std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl; |
| 211 | std::exit(EXIT_FAILURE); |
| 212 | } |
| 213 | |
| 214 | unsigned int len = 0; |
| 215 | bytes_to_read = sizeof(len); |
| 216 | bytes_read = read(rpipe, &len, bytes_to_read); |
| 217 | if (bytes_read <= 0) { |
| 218 | const int err = errno; |
| 219 | std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << std::endl; |
| 220 | std::exit(EXIT_FAILURE); |
| 221 | } |
| 222 | if (bytes_read != bytes_to_read) { |
| 223 | std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl; |
| 224 | std::exit(EXIT_FAILURE); |
| 225 | } |
| 226 | |
| 227 | std::string buf(len, '\0'); |
| 228 | if (len > 0) { // TODO: unexpected - write a warning? |
| 229 | char *data_start = &buf[0]; |
| 230 | bytes_to_read = len; |
| 231 | do { |
| 232 | bytes_read = read(rpipe, data_start, bytes_to_read); |
| 233 | if (bytes_read <= 0) { |
| 234 | const int err = errno; |
| 235 | std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl; |
| 236 | std::exit(EXIT_FAILURE); |
| 237 | } |
nothing calls this directly
no test coverage detected