@@ -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
@@ -3397,32 +3397,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 */
@@ -2707,6 +2707,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 -----*/
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@gmail.com> --- 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(-)