From b7f432808d5226e8f55a8150531528494117fc52 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Fri, 1 May 2015 13:17:31 +0800 Subject: [PATCH] systest_runnable: adjust argument to suite Preforker Signed-off-by: Haomai Wang --- src/common/Preforker.h | 6 +++--- src/test/system/systest_runnable.cc | 29 +++++++++++++---------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/common/Preforker.h b/src/common/Preforker.h index 5970700df1f2e..4b182389afc4c 100644 --- a/src/common/Preforker.h +++ b/src/common/Preforker.h @@ -45,8 +45,8 @@ public: int prefork(std::string &err) { assert(!forked); int r = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); + std::ostringstream oss; if (r < 0) { - std::ostringstream oss; oss << "[" << getpid() << "]: unable to create socketpair: " << cpp_strerror(errno); err = oss.str(); return r; @@ -81,7 +81,7 @@ public: return childpid != 0; } - int parent_wait(std::string &err) { + int parent_wait(std::string &err_msg) { assert(forked); int r = -1; @@ -111,7 +111,7 @@ public: oss << "[" << getpid() << "]" << " returned exit_status " << cpp_strerror(err); } } - err = oss.str(); + err_msg = oss.str(); return err; } diff --git a/src/test/system/systest_runnable.cc b/src/test/system/systest_runnable.cc index 32fb36b598721..c7ed6aa72a2dc 100644 --- a/src/test/system/systest_runnable.cc +++ b/src/test/system/systest_runnable.cc @@ -80,27 +80,29 @@ start() if (m_started) { return -EDOM; } + int ret; bool use_threads = SysTestSettings::inst().use_threads(); if (use_threads) { - int ret = pthread_create(&m_pthread, NULL, systest_runnable_pthread_helper, + ret = pthread_create(&m_pthread, NULL, systest_runnable_pthread_helper, static_cast(this)); if (ret) return ret; m_started = true; - return 0; - } - else { - prefork.prefork(); + } else { + std::string err_msg; + ret = preforker.prefork(err_msg); + if (ret < 0) + preforker.exit(ret); - if (prefork.is_child()) { + if (preforker.is_child()) { m_started = true; void *retptr = systest_runnable_pthread_helper(static_cast(this)); - prefork.exit((int)(uintptr_t)retptr); + preforker.exit((int)(uintptr_t)retptr); } else { m_started = true; - return 0; } } + return 0; } std::string SysTestRunnable:: @@ -127,14 +129,9 @@ join() } return ""; } else { - ret = preforker.parent_wait(); - if (ret < 0) { - ostringstream oss; - oss << get_id_str() << " waitpid error: " << cpp_strerror(err); - return oss.str(); - } else { - return ""; - } + std::string err_msg; + ret = preforker.parent_wait(err_msg); + return err_msg; } } -- 2.39.5