[PATCH v2 3/4] Add a 'send-process-signal' command to virsh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

* tools/virsh.c: Add send-process-signal
* tools/virsh.pod: Document new command

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/virsh-domain.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod      |  27 ++++++++++++++
 2 files changed, 130 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 6d5a0ec..e22255a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5901,6 +5901,108 @@ cleanup:
 }
 
 /*
+ * "send-process-signal" command
+ */
+static const vshCmdInfo info_send_process_signal[] = {
+    {"help", N_("Send signals to processes") },
+    {"desc", N_("Send signals to processes in the guest") },
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_send_process_signal[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"pid", VSH_OT_DATA, VSH_OFLAG_REQ, N_("the process ID") },
+    {"signame", VSH_OT_DATA, VSH_OFLAG_REQ, N_("the signal number or name") },
+    {NULL, 0, 0, NULL}
+};
+
+VIR_ENUM_DECL(virDomainProcessSignal)
+VIR_ENUM_IMPL(virDomainProcessSignal,
+              VIR_DOMAIN_PROCESS_SIGNAL_LAST,
+              "nop", "hup", "int", "quit", "ill", /* 0-4 */
+              "trap", "abrt", "bus", "fpe", "kill", /* 5-9 */
+              "usr1", "segv", "usr2", "pipe", "alrm", /* 10-14 */
+              "term", "stkflt", "chld", "cont", "stop", /* 15-19 */
+              "tstp", "ttin", "ttou", "urg", "xcpu", /* 20-24 */
+              "xfsz", "vtalrm", "prof", "winch", "poll", /* 25-29 */
+              "pwr", "sys", "rt0","rt1", "rt2",  /* 30-34 */
+              "rt3", "rt4", "rt5", "rt6", "rt7",  /* 35-39 */
+              "rt8", "rt9", "rt10", "rt11", "rt12",  /* 40-44 */
+              "rt13", "rt14", "rt15", "rt16", "rt17",  /* 45-49 */
+              "rt18", "rt19", "rt20", "rt21", "rt22",  /* 50-54 */
+              "rt23", "rt24", "rt25", "rt26", "rt27",  /* 55-59 */
+              "rt28", "rt29", "rt30", "rt31", "rt32")  /* 60-64 */
+
+static int getSignalNumber(vshControl *ctl, const char *signame)
+{
+    size_t i;
+    int signum;
+    char *lower = vshStrdup(ctl, signame);
+
+    for (i = 0 ; signame[i] ; i++)
+        lower[i] = c_tolower(signame[i]);
+
+    if (virStrToLong_i(signame, NULL, 10, &signum) >= 0)
+        goto cleanup;
+
+    if (STRPREFIX(signame, "sig"))
+        signame += 3;
+    else if (STRPREFIX(signame, "sig_"))
+        signame += 4;
+
+    if ((signum = virDomainProcessSignalTypeFromString(signame)) >= 0)
+        goto cleanup;
+
+    signum = -1;
+cleanup:
+    VIR_FREE(lower);
+    return signum;
+}
+
+static bool
+cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    int ret = false;
+    const char *pidstr;
+    const char *signame;
+    long long pid_value;
+    int signum;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (vshCommandOptString(cmd, "pid", &pidstr) <= 0) {
+        vshError(ctl, "%s", _("missing argument"));
+        return false;
+    }
+
+    if (vshCommandOptString(cmd, "signame", &signame) <= 0) {
+        vshError(ctl, "%s", _("missing argument"));
+        return false;
+    }
+
+    if (virStrToLong_ll(pidstr, NULL, 10, &pid_value) < 0) {
+        vshError(ctl, _("malformed PID value: %s"), pidstr);
+        goto cleanup;
+    }
+
+    if ((signum = getSignalNumber(ctl, signame)) < 0) {
+        vshError(ctl, _("malformed signal name: %s"), signame);
+        goto cleanup;
+    }
+
+    if (virDomainSendProcessSignal(dom, pid_value, signum, 0) < 0)
+        goto cleanup;
+
+    ret = true;
+
+cleanup:
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
  * "setmem" command
  */
 static const vshCmdInfo info_setmem[] = {
@@ -8398,6 +8500,7 @@ const vshCmdDef domManagementCmds[] = {
     {"edit", cmdEdit, opts_edit, info_edit, 0},
     {"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi, 0},
     {"send-key", cmdSendKey, opts_send_key, info_send_key, 0},
+    {"send-process-signal", cmdSendProcessSignal, opts_send_process_signal, info_send_process_signal, 0},
     {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave, 0},
     {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove,
      info_managedsaveremove, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 353af66..1708cc4 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1393,6 +1393,33 @@ B<Examples>
   # send a tab, held for 1 second
   virsh send-key --holdtime 1000 0xf
 
+=item B<send-process-signal> I<domain-id> [I<--host-pid>] I<pid> I<signame>
+
+Send a signal I<signame> to the process identified by I<pid> running in
+the virtual domain I<domain-id>. The I<pid> is a process ID in the virtual
+domain namespace.
+
+The I<signame> argument may be either an integer signal constant number,
+or one of the symbolic names:
+
+    "nop", "hup", "int", "quit", "ill",
+    "trap", "abrt", "bus", "fpe", "kill",
+    "usr1", "segv", "usr2", "pipe", "alrm",
+    "term", "stkflt", "chld", "cont", "stop",
+    "tstp", "ttin", "ttou", "urg", "xcpu",
+    "xfsz", "vtalrm", "prof", "winch", "poll",
+    "pwr", "sys", "rtmin"
+
+The symbol name may optionally be prefixed with 'sig'. The 'rtmin' signal
+also allows an optional suffix "+<number>" to refer to other real time
+signals.
+
+B<Examples>
+  virsh send-process-signal myguest 1 15
+  virsh send-process-signal myguest 1 term
+  virsh send-process-signal myguest 1 sigterm
+  virsh send-process-signal myguest 1 rtmin+12
+
 =item B<setmem> I<domain> B<size> [[I<--config>] [I<--live>] |
 [I<--current>]]
 
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]