[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v6 12/18] libxl: Refactor kill_device_model to libxl__kill_xs_path
Move kill_device_model to libxl__kill_xs_path so we have a helper to kill a process from a pid stored in xenstore. We'll be using it to kill vchan-qmp-proxy. libxl__kill_xs_path takes a "what" string for use in printing error messages. kill_device_model is retained in libxl_dm.c to provide the string. Signed-off-by: Jason Andryuk <jandryuk@xxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- Changes in v6: - Add Acked-by: Ian Jackson --- tools/libxl/libxl_aoutils.c | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_dm.c | 27 +-------------------------- tools/libxl/libxl_internal.h | 3 +++ 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c index 1be858c93c..c4c095a5ba 100644 --- a/tools/libxl/libxl_aoutils.c +++ b/tools/libxl/libxl_aoutils.c @@ -626,6 +626,38 @@ void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what) what, (unsigned long)pid, sig); } +/* Generic function to signal (HUP) a pid stored in xenstore */ +int libxl__kill_xs_path(libxl__gc *gc, const char *xs_path_pid, + const char *what) +{ + const char *xs_pid; + int ret, pid; + + ret = libxl__xs_read_checked(gc, XBT_NULL, xs_path_pid, &xs_pid); + if (ret || !xs_pid) { + LOG(ERROR, "unable to find %s pid in %s", what, xs_path_pid); + ret = ret ? : ERROR_FAIL; + goto out; + } + pid = atoi(xs_pid); + + ret = kill(pid, SIGHUP); + if (ret < 0 && errno == ESRCH) { + LOG(ERROR, "%s already exited", what); + ret = 0; + } else if (ret == 0) { + LOG(DEBUG, "%s signaled", what); + ret = 0; + } else { + LOGE(ERROR, "failed to kill %s [%d]", what, pid); + ret = ERROR_FAIL; + goto out; + } + +out: + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index a4f8866d33..478e6540df 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -3235,32 +3235,7 @@ out: /* Generic function to signal a Qemu instance to exit */ static int kill_device_model(libxl__gc *gc, const char *xs_path_pid) { - const char *xs_pid; - int ret, pid; - - ret = libxl__xs_read_checked(gc, XBT_NULL, xs_path_pid, &xs_pid); - if (ret || !xs_pid) { - LOG(ERROR, "unable to find device model pid in %s", xs_path_pid); - ret = ret ? : ERROR_FAIL; - goto out; - } - pid = atoi(xs_pid); - - ret = kill(pid, SIGHUP); - if (ret < 0 && errno == ESRCH) { - LOG(ERROR, "Device Model already exited"); - ret = 0; - } else if (ret == 0) { - LOG(DEBUG, "Device Model signaled"); - ret = 0; - } else { - LOGE(ERROR, "failed to kill Device Model [%d]", pid); - ret = ERROR_FAIL; - goto out; - } - -out: - return ret; + return libxl__kill_xs_path(gc, xs_path_pid, "Device Model"); } /* Helper to destroy a Qdisk backend */ diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index f2f76439ec..c939557b2e 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2711,6 +2711,9 @@ int libxl__async_exec_start(libxl__async_exec_state *aes); bool libxl__async_exec_inuse(const libxl__async_exec_state *aes); _hidden void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what); +/* kill SIGHUP a pid stored in xenstore */ +_hidden int libxl__kill_xs_path(libxl__gc *gc, const char *xs_path_pid, + const char *what); /*----- device addition/removal -----*/ -- 2.25.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |