From d5df4b979045fa94a45bfa3b2b820285bdc5de12 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Thu, 14 Jul 2011 19:05:05 +0200 Subject: Handle nbd-server startup error --- src/client/main.cpp | 2 +- src/worker/main.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/main.cpp b/src/client/main.cpp index dfec059..10a497b 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) } else if (ret == GEARMAN_WORK_FAIL) { - cerr << "[ERROR] " << msg << endl; + cerr << "[REMOTE ERROR] " << msg << endl; cerr << "[ERROR] Work failed" << endl; free(result); } diff --git a/src/worker/main.cpp b/src/worker/main.cpp index ff97041..a0d6cb4 100644 --- a/src/worker/main.cpp +++ b/src/worker/main.cpp @@ -70,11 +70,22 @@ static void *start_nbd_server(gearman_job_st *job, void *context, stringstream command; command << "nbd-server " << _nbd_server_port << " " << *image; cout << "[DEBUG] " << "Running command: " << command.str() << endl; - system(command.str().c_str()); + int ret = system(command.str().c_str()); + if (ret == 0) + { + current_port = _nbd_server_port; + _map[*image] = _nbd_server_port; + _nbd_server_port++; + } + else + { + cerr << "[ERROR] Command execution failed, aborting!" << endl; + char msg[] = "Couldn't start nbd-server"; + gearman_job_send_data(job, msg, sizeof(msg)); + *ret_ptr = GEARMAN_WORK_FAIL; + return NULL; + } - current_port = _nbd_server_port; - _map[*image] = _nbd_server_port; - _nbd_server_port++; } // send port number to client -- cgit v1.2.3-55-g7522