From: "Daniel P. Berrange" <berrange(a)redhat.com>
Add an API for sending signals to arbitrary processes in the
guest OS. This is primarily useful for container based virt,
but can be used for machine virt too, if there is a suitable
guest agent,
* include/libvirt/libvirt.h.in: Add virDomainSendProcessSignal
and virDomainProcessSignal enum
* src/driver.h: Driver entry point
* src/libvirt.c, src/libvirt_public.syms: Impl for new API
---
include/libvirt/libvirt.h.in | 97 ++++++++++++++++++++++++++++++++++++++++++++
src/driver.h | 7 ++++
src/libvirt.c | 84 ++++++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 1 +
4 files changed, 189 insertions(+)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index bd03315..0f6ff4c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2989,6 +2989,103 @@ int virDomainSendKey(virDomainPtr domain,
unsigned int flags);
/*
+ * These just happen to match Linux signal numbers. The numbers
+ * will be mapped to whatever the SIGNUM is in the guest OS in
+ * question by the agent delivering the signal. The names are
+ * based on the POSIX / XSI signal standard though.
+ *
+ * Do not rely on all values matching Linux though. It is possible
+ * this enum might be extended with new signals which have no
+ * mapping in Linux.
+ */
+typedef enum {
+ VIR_DOMAIN_PROCESS_SIGNAL_NOP = 0, /* No constant in POSIX/Linux */
+ VIR_DOMAIN_PROCESS_SIGNAL_HUP = 1, /* SIGHUP */
+ VIR_DOMAIN_PROCESS_SIGNAL_INT = 2, /* SIGINT */
+ VIR_DOMAIN_PROCESS_SIGNAL_QUIT = 3, /* SIGQUIT */
+ VIR_DOMAIN_PROCESS_SIGNAL_ILL = 4, /* SIGILL */
+ VIR_DOMAIN_PROCESS_SIGNAL_TRAP = 5, /* SIGTRAP */
+ VIR_DOMAIN_PROCESS_SIGNAL_ABRT = 6, /* SIGABRT */
+ VIR_DOMAIN_PROCESS_SIGNAL_BUS = 7, /* SIGBUS */
+ VIR_DOMAIN_PROCESS_SIGNAL_FPE = 8, /* SIGFPE */
+ VIR_DOMAIN_PROCESS_SIGNAL_KILL = 9, /* SIGKILL */
+
+ VIR_DOMAIN_PROCESS_SIGNAL_USR1 = 10, /* SIGUSR1 */
+ VIR_DOMAIN_PROCESS_SIGNAL_SEGV = 11, /* SIGSEGV */
+ VIR_DOMAIN_PROCESS_SIGNAL_USR2 = 12, /* SIGUSR2 */
+ VIR_DOMAIN_PROCESS_SIGNAL_PIPE = 13, /* SIGPIPE */
+ VIR_DOMAIN_PROCESS_SIGNAL_ALRM = 14, /* SIGALRM */
+ VIR_DOMAIN_PROCESS_SIGNAL_TERM = 15, /* SIGTERM */
+ VIR_DOMAIN_PROCESS_SIGNAL_STKFLT = 16, /* Not in POSIX (SIGSTKFLT on Linux )*/
+ VIR_DOMAIN_PROCESS_SIGNAL_CHLD = 17, /* SIGCHLD */
+ VIR_DOMAIN_PROCESS_SIGNAL_CONT = 18, /* SIGCONT */
+ VIR_DOMAIN_PROCESS_SIGNAL_STOP = 19, /* SIGSTOP */
+
+ VIR_DOMAIN_PROCESS_SIGNAL_TSTP = 20, /* SIGTSTP */
+ VIR_DOMAIN_PROCESS_SIGNAL_TTIN = 21, /* SIGTTIN */
+ VIR_DOMAIN_PROCESS_SIGNAL_TTOU = 22, /* SIGTTOU */
+ VIR_DOMAIN_PROCESS_SIGNAL_URG = 23, /* SIGURG */
+ VIR_DOMAIN_PROCESS_SIGNAL_XCPU = 24, /* SIGXCPU */
+ VIR_DOMAIN_PROCESS_SIGNAL_XFSZ = 25, /* SIGXFSZ */
+ VIR_DOMAIN_PROCESS_SIGNAL_VTALRM = 26, /* SIGVTALRM */
+ VIR_DOMAIN_PROCESS_SIGNAL_PROF = 27, /* SIGPROF */
+ VIR_DOMAIN_PROCESS_SIGNAL_WINCH = 28, /* Not in POSIX (SIGWINCH on Linux) */
+ VIR_DOMAIN_PROCESS_SIGNAL_POLL = 29, /* SIGPOLL (also known as SIGIO on Linux)
*/
+
+ VIR_DOMAIN_PROCESS_SIGNAL_PWR = 30, /* Not in POSIX (SIGPWR on Linux */
+ VIR_DOMAIN_PROCESS_SIGNAL_SYS = 31, /* SIGSYS (also known as SIGUNUSED on
Linux ) */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT0 = 32, /* SIGRTMIN */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT1 = 33, /* SIGRTMIN + 1 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT2 = 34, /* SIGRTMIN + 2 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT3 = 35, /* SIGRTMIN + 3 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT4 = 36, /* SIGRTMIN + 4 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT5 = 37, /* SIGRTMIN + 5 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT6 = 38, /* SIGRTMIN + 6 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT7 = 39, /* SIGRTMIN + 7 */
+
+ VIR_DOMAIN_PROCESS_SIGNAL_RT8 = 40, /* SIGRTMIN + 8 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT9 = 41, /* SIGRTMIN + 9 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT10 = 42, /* SIGRTMIN + 10 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT11 = 43, /* SIGRTMIN + 11 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT12 = 44, /* SIGRTMIN + 12 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT13 = 45, /* SIGRTMIN + 13 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT14 = 46, /* SIGRTMIN + 14 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT15 = 47, /* SIGRTMIN + 15 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT16 = 48, /* SIGRTMIN + 16 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT17 = 49, /* SIGRTMIN + 17 */
+
+ VIR_DOMAIN_PROCESS_SIGNAL_RT18 = 50, /* SIGRTMIN + 18 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT19 = 51, /* SIGRTMIN + 19 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT20 = 52, /* SIGRTMIN + 20 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT21 = 53, /* SIGRTMIN + 21 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT22 = 54, /* SIGRTMIN + 22 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT23 = 55, /* SIGRTMIN + 23 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT24 = 56, /* SIGRTMIN + 24 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT25 = 57, /* SIGRTMIN + 25 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT26 = 58, /* SIGRTMIN + 26 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT27 = 59, /* SIGRTMIN + 27 */
+
+ VIR_DOMAIN_PROCESS_SIGNAL_RT28 = 60, /* SIGRTMIN + 28 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT29 = 61, /* SIGRTMIN + 29 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT30 = 62, /* SIGRTMIN + 30 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT31 = 63, /* SIGRTMIN + 31 */
+ VIR_DOMAIN_PROCESS_SIGNAL_RT32 = 64, /* SIGRTMIN + 32 / SIGRTMAX */
+
+#ifdef VIR_ENUM_SENTINELS
+ /* This is the "last" signal only in so much as none
+ * of the latter ones have named constants. They are
+ * just numeric offsets from RTMIN upwards
+ */
+ VIR_DOMAIN_PROCESS_SIGNAL_LAST
+#endif
+} virDomainProcessSignal;
+
+int virDomainSendProcessSignal(virDomainPtr domain,
+ long long pid_value,
+ unsigned int signum,
+ unsigned int flags);
+
+/*
* Deprecated calls
*/
virDomainPtr virDomainCreateLinux (virConnectPtr conn,
diff --git a/src/driver.h b/src/driver.h
index 5163840..9add96c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -732,6 +732,12 @@ typedef int
int nkeycodes,
unsigned int flags);
+typedef int
+ (*virDrvDomainSendProcessSignal)(virDomainPtr dom,
+ long long pid_value,
+ unsigned int signum,
+ unsigned int flags);
+
typedef char *
(*virDrvDomainMigrateBegin3)
(virDomainPtr domain,
@@ -1100,6 +1106,7 @@ struct _virDriver {
virDrvNodeSetMemoryParameters nodeSetMemoryParameters;
virDrvNodeGetCPUMap nodeGetCPUMap;
virDrvDomainFSTrim domainFSTrim;
+ virDrvDomainSendProcessSignal domainSendProcessSignal;
};
typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index 4581394..fa3d58f 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8590,6 +8590,90 @@ error:
return -1;
}
+
+/**
+ * virDomainSendProcessSignal:
+ * @domain: pointer to domain object
+ * @pid_value: a positive integer process ID, or negative integer process group ID
+ * @signum: a signal from the virDomainProcessSignal enum
+ * @flags: one of the virDomainProcessSignalFlag values
+ *
+ * Send a signal to the designated process in the guest
+ *
+ * The signal numbers must be taken from the virDomainProcessSignal
+ * enum. These will be translated to the corresponding signal
+ * number for the guest OS, by the guest agent delivering the
+ * signal. If there is no mapping from virDomainProcessSignal to
+ * the native OS signals, this API will report an error
+ *
+ * If @pid_value is an integer greater than zero, it is
+ * treated as a process ID. If @pid_value is an integer
+ * less than zero, it is treated as a process group ID.
+ * All the @pid_value numbers are from the container/guest
+ * namespace. The value zero is not valid.
+ *
+ * Not all hypervisors will support sending signals to
+ * arbitrary processes or process groups. If this API is
+ * implemented the minimum requirement is to be able to
+ * use @pid_value==1 (ie kill init). No other value is
+ * required to be supported.
+ *
+ * If the @signum is VIR_DOMAIN_PROCESS_SIGNAL_NOP then this
+ * API will simply report whether the process is running in
+ * the container/guest.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int virDomainSendProcessSignal(virDomainPtr domain,
+ long long pid_value,
+ unsigned int signum,
+ unsigned int flags)
+{
+ virConnectPtr conn;
+ VIR_DOMAIN_DEBUG(domain, "pid=%lld, signum=%u flags=%x",
+ pid_value, signum, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+ virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+
+ virCheckNonZeroArgGoto(pid_value, error);
+
+ if (domain->conn->flags & VIR_CONNECT_RO) {
+ virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+
+ if (signum > VIR_DOMAIN_PROCESS_SIGNAL_LAST) {
+ virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ conn = domain->conn;
+
+ if (conn->driver->domainSendProcessSignal) {
+ int ret;
+ ret = conn->driver->domainSendProcessSignal(domain,
+ pid_value,
+ signum,
+ flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(domain->conn);
+ return -1;
+}
+
+
/**
* virDomainSetVcpus:
* @domain: pointer to domain object, or NULL for Domain0
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index f699e93..e3d63d3 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -577,6 +577,7 @@ LIBVIRT_1.0.0 {
LIBVIRT_1.0.1 {
global:
virDomainFSTrim;
+ virDomainSendProcessSignal;
} LIBVIRT_1.0.0;
# .... define new API here using predicted next version number ....
--
1.7.11.7