From: Haomai Wang Date: Fri, 1 May 2015 03:59:07 +0000 (+0800) Subject: systest_runnable: Use Preforker to do fork X-Git-Tag: v9.0.1~26^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3f969d60cd80198207effa70580e82e080c36a0a;p=ceph.git systest_runnable: Use Preforker to do fork Signed-off-by: Haomai Wang --- diff --git a/src/common/Preforker.h b/src/common/Preforker.h index ea840597f5a5..72f992435dba 100644 --- a/src/common/Preforker.h +++ b/src/common/Preforker.h @@ -7,10 +7,12 @@ #include #include #include +#include #include #ifdef WITH_LTTNG #include #endif +#include "include/assert.h" #include "common/safe_io.h" #include "common/errno.h" @@ -82,7 +84,7 @@ public: cerr << "[" << getpid() << "]: " << cpp_strerror(err) << std::endl; } else { // wait for child to exit - waitpid(childpid, NULL, 0); + r = waitpid(childpid, NULL, 0); } return r; } diff --git a/src/test/system/systest_runnable.cc b/src/test/system/systest_runnable.cc index 55cab0aef9dd..32fb36b59872 100644 --- a/src/test/system/systest_runnable.cc +++ b/src/test/system/systest_runnable.cc @@ -58,7 +58,6 @@ SysTestRunnable(int argc, const char **argv) m_started = false; m_id = m_highest_id.inc(); memset(&m_pthread, 0, sizeof(m_pthread)); - m_pid = 0; update_id_str(false); set_argv(argc, argv); } @@ -91,20 +90,14 @@ start() return 0; } else { - pid_t pid = fork(); - if (pid == -1) { - int err = errno; - return -err; - } - else if (pid == 0) { + prefork.prefork(); + + if (prefork.is_child()) { m_started = true; - m_pid = getpid(); void *retptr = systest_runnable_pthread_helper(static_cast(this)); - exit((int)(uintptr_t)retptr); - } - else { + prefork.exit((int)(uintptr_t)retptr); + } else { m_started = true; - m_pid = pid; return 0; } } @@ -116,10 +109,11 @@ join() if (!m_started) { return "SysTestRunnable was never started."; } + int ret; bool use_threads = SysTestSettings::inst().use_threads(); if (use_threads) { void *ptrretval; - int ret = pthread_join(m_pthread, &ptrretval); + ret = pthread_join(m_pthread, &ptrretval); if (ret) { ostringstream oss; oss << "pthread_join failed with error " << ret; @@ -132,34 +126,13 @@ join() return oss.str(); } return ""; - } - else { - int status; - printf("waitpid(%d)\n", m_pid); - pid_t pid = waitpid(m_pid, &status, 0); - if (pid == -1) { - int err = errno; + } else { + ret = preforker.parent_wait(); + if (ret < 0) { ostringstream oss; oss << get_id_str() << " waitpid error: " << cpp_strerror(err); return oss.str(); - } - else if (WIFSIGNALED(status)) { - ostringstream oss; - oss << get_id_str() << " exited with a signal"; - return oss.str(); - } - else if (!WIFEXITED(status)) { - ostringstream oss; - oss << get_id_str() << " did not exit normally"; - return oss.str(); - } - else { - int exit_status = WEXITSTATUS(status); - if (exit_status != 0) { - ostringstream oss; - oss << get_id_str() << " returned exit_status " << exit_status; - return oss.str(); - } + } else { return ""; } } diff --git a/src/test/system/systest_runnable.h b/src/test/system/systest_runnable.h index 2164fa78f9ce..bd7d2586bc31 100644 --- a/src/test/system/systest_runnable.h +++ b/src/test/system/systest_runnable.h @@ -20,6 +20,8 @@ #include #include +#include "common/Preforker.h" + #define RETURN1_IF_NOT_VAL(expected, expr) \ do {\ int _rinv_ret = expr;\ @@ -77,11 +79,11 @@ private: friend void* systest_runnable_pthread_helper(void *arg); + Preforker preforker; const char **m_argv_orig; bool m_started; int m_id; pthread_t m_pthread; - int m_pid; char m_id_str[ID_STR_SZ]; };