|
|
|
@@ -588,26 +588,31 @@ Status CacheAdminArgHandler::StartServer(CommandId command_id) { |
|
|
|
close(fd[1]); |
|
|
|
(void)dup2(fd[0], STDIN_FILENO); |
|
|
|
close(fd[0]); |
|
|
|
int status; |
|
|
|
if (waitpid(pid, &status, 0) == -1) { |
|
|
|
RETURN_STATUS_UNEXPECTED("waitpid fails. errno = " + std::to_string(errno)); |
|
|
|
} |
|
|
|
std::string msg; |
|
|
|
const int32_t buf_sz = 1024; |
|
|
|
msg.resize(buf_sz); |
|
|
|
auto n = read(0, msg.data(), buf_sz); |
|
|
|
// keep reading until we drain the pipe |
|
|
|
while (n > 0) { |
|
|
|
msg.resize(n); |
|
|
|
// Not an error, some info message goes to stdout |
|
|
|
std::cout << msg; |
|
|
|
msg.resize(buf_sz); |
|
|
|
n = read(0, msg.data(), buf_sz); |
|
|
|
} |
|
|
|
if (n < 0) { |
|
|
|
std::string err_msg = "Failed to read from pipeline " + std::to_string(errno); |
|
|
|
RETURN_STATUS_UNEXPECTED(err_msg); |
|
|
|
} |
|
|
|
msg.resize(n); |
|
|
|
|
|
|
|
int status; |
|
|
|
if (waitpid(pid, &status, 0) == -1) { |
|
|
|
RETURN_STATUS_UNEXPECTED("waitpid fails. errno = " + std::to_string(errno)); |
|
|
|
} |
|
|
|
if (WIFEXITED(status)) { |
|
|
|
auto exit_status = WEXITSTATUS(status); |
|
|
|
if (exit_status) { |
|
|
|
return Status(StatusCode::kMDUnexpectedError, msg); |
|
|
|
} else { |
|
|
|
// Not an error, some info message goes to stdout |
|
|
|
std::cout << msg << std::endl; |
|
|
|
} |
|
|
|
} |
|
|
|
return Status::OK(); |
|
|
|
|