rbd: propagate rbd-wnbd errors

This change updates the "rbd device" commands, propagating
rbd-wnbd.exe exit codes.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
This commit is contained in:
Lucian Petrut 2021-01-29 13:38:19 +00:00
parent afa7b532b2
commit 8d64c7cf42
2 changed files with 7 additions and 3 deletions

View File

@ -142,18 +142,20 @@ int SubProcess::join() {
close(stdout_pipe_in_fd);
close(stderr_pipe_in_fd);
DWORD status = 0;
int status = 0;
if (WaitForSingleObject(proc_handle, INFINITE) != WAIT_FAILED) {
if (!GetExitCodeProcess(proc_handle, &status)) {
errstr << cmd << ": Could not get exit code: " << pid
<< ". Error code: " << GetLastError();
status = -ECHILD;
} else if (status) {
errstr << cmd << ": exit status: " << status;
}
} else {
errstr << cmd << ": Waiting for child process failed: " << pid
<< ". Error code: " << GetLastError();
status = -ECHILD;
}
close_h(proc_handle);

View File

@ -53,9 +53,11 @@ static int call_wnbd_cmd(const po::variables_map &vm,
if (process.spawn()) {
std::cerr << "rbd: failed to run rbd-wnbd: " << process.err() << std::endl;
return -EINVAL;
} else if (process.join()) {
}
int exit_code = process.join();
if (exit_code) {
std::cerr << "rbd: rbd-wnbd failed with error: " << process.err() << std::endl;
return -EINVAL;
return exit_code;
}
return 0;