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@gmail.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
Jason Andryuk authored and Wei Liu committed 2020-05-19 16:19:15 +01:00
1 parent 14fe3ace50
commit 379ab27086
3 files changed
+36 -26

No files matched your search

+32
View File
@@ -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
+1 -26
View File
@@ -3225,32 +3225,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 */
+3
View File
@@ -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 -----*/
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.