]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Move virProcessKill into virprocess.{h, c}
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 12 Sep 2013 16:00:03 +0000 (17:00 +0100)
committerEric Blake <eblake@redhat.com>
Thu, 19 Sep 2013 03:10:20 +0000 (21:10 -0600)
There are a number of process related functions spread
across multiple files. Start to consolidate them by
creating a virprocess.{c,h} file

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit e5e2b65cf86ea49eba76b3c274e3b9d2177485bc)
Signed-off-by: Eric Blake <eblake@redhat.com>
Conflicts:
src/qemu/qemu_monitor.c
src/util/util.h

src/Makefile.am
src/libvirt_private.syms
src/qemu/qemu_agent.c
src/qemu/qemu_monitor.c
src/qemu/qemu_process.c
src/uml/uml_driver.c
src/util/util.c
src/util/util.h
src/util/virprocess.c [new file with mode: 0644]
src/util/virprocess.h [new file with mode: 0644]

index b5da2fb475b51090a558162c038436220fb54ce1..6656fa0a40e46bf26802028dfa817eed4145e35a 100644 (file)
@@ -85,6 +85,7 @@ UTIL_SOURCES =                                                        \
                util/virfile.c util/virfile.h                   \
                util/virnodesuspend.c util/virnodesuspend.h     \
                util/virpidfile.c util/virpidfile.h             \
+               util/virprocess.c util/virprocess.h             \
                util/virtypedparam.c util/virtypedparam.h       \
                util/xml.c util/xml.h                           \
                util/virterror.c util/virterror_internal.h      \
index 13a732be28eea299dd89300e3907b8e8cf895b90..95f254393adf762a0939fcfdd1af04c860b261b5 100644 (file)
@@ -1453,6 +1453,9 @@ virPidFileDelete;
 virPidFileDeletePath;
 
 
+# virprocess.h
+virProcessKill;
+
 # virrandom.h
 virRandomBits;
 virRandomGenerateWWN;
index 1e3e327443e6c803fb17f928d5a042c5400709cf..5618ddf77d0b25dfc4ed0282d42cac8927feba93 100644 (file)
@@ -39,6 +39,7 @@
 #include "virterror_internal.h"
 #include "json.h"
 #include "virfile.h"
+#include "virprocess.h"
 #include "virtime.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
index cfe1a25a811037bb5397602546b09711c1dffa71..265f03ce5ec0e310cd0a44888beca3593c279748 100644 (file)
@@ -36,6 +36,7 @@
 #include "memory.h"
 #include "logging.h"
 #include "virfile.h"
+#include "virprocess.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
index 7fc87f4cbe3eb630cbe57746303d4bccaa10337e..a14fc574b19f527212140ec250f9341bb7eb57ca 100644 (file)
@@ -61,6 +61,7 @@
 #include "locking/domain_lock.h"
 #include "network/bridge_driver.h"
 #include "uuid.h"
+#include "virprocess.h"
 #include "virtime.h"
 #include "virnetdevtap.h"
 
index 8db78b8ceff92f265a3f4f93058eaf2f37b13ffc..83a31a99177fb505193ff4eb9c53add56c6452e2 100644 (file)
@@ -63,6 +63,7 @@
 #include "configmake.h"
 #include "virnetdevtap.h"
 #include "virnodesuspend.h"
+#include "virprocess.h"
 #include "viruri.h"
 
 #define VIR_FROM_THIS VIR_FROM_UML
index e1f8d1e36fc4cee529b1ff095595992710219a6d..b807c5a23283752900529cfcd0fdab3ad41ca5bd 100644 (file)
@@ -2132,63 +2132,6 @@ check_and_return:
     return result;
 }
 
-/* send signal to a single process */
-int virProcessKill(pid_t pid, int sig)
-{
-    if (pid <= 1) {
-        errno = ESRCH;
-        return -1;
-    }
-
-#ifdef WIN32
-    /* Mingw / Windows don't have many signals (AFAIK) */
-    switch (sig) {
-    case SIGINT:
-        /* This does a Ctrl+C equiv */
-        if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) {
-            errno = ESRCH;
-            return -1;
-        }
-        break;
-
-    case SIGTERM:
-        /* Since TerminateProcess is closer to SIG_KILL, we do
-         * a Ctrl+Break equiv which is more pleasant like the
-         * good old unix SIGTERM/HUP
-         */
-        if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) {
-            errno = ESRCH;
-            return -1;
-        }
-        break;
-
-    default:
-    {
-        HANDLE proc;
-        proc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
-        if (!proc) {
-            errno = ESRCH; /* Not entirely accurate, but close enough */
-            return -1;
-        }
-
-        /*
-         * TerminateProcess is more or less equiv to SIG_KILL, in that
-         * a process can't trap / block it
-         */
-        if (sig != 0 && !TerminateProcess(proc, sig)) {
-            errno = ESRCH;
-            return -1;
-        }
-        CloseHandle(proc);
-    }
-    }
-    return 0;
-#else
-    return kill(pid, sig);
-#endif
-}
-
-
 #ifdef HAVE_GETPWUID_R
 enum {
     VIR_USER_ENT_DIRECTORY,
index 838bff72a0ad70927001dfc8cc3470fa2e8a4ae3..c63f5fb52c27355b0a4bdc819ef6d82c54aca96a 100644 (file)
@@ -225,7 +225,6 @@ static inline int getgid (void) { return 0; }
 
 char *virGetHostname(virConnectPtr conn);
 
-int virProcessKill(pid_t pid, int sig);
 
 char *virGetUserDirectory(uid_t uid);
 char *virGetUserName(uid_t uid);
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
new file mode 100644 (file)
index 0000000..e7db68f
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * virprocess.c: interaction with processes
+ *
+ * Copyright (C) 2010-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include <config.h>
+
+#include <signal.h>
+#include <errno.h>
+
+#include "virprocess.h"
+
+/* send signal to a single process */
+int virProcessKill(pid_t pid, int sig)
+{
+    if (pid <= 1) {
+        errno = ESRCH;
+        return -1;
+    }
+
+#ifdef WIN32
+    /* Mingw / Windows don't have many signals (AFAIK) */
+    switch (sig) {
+    case SIGINT:
+        /* This does a Ctrl+C equiv */
+        if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) {
+            errno = ESRCH;
+            return -1;
+        }
+        break;
+
+    case SIGTERM:
+        /* Since TerminateProcess is closer to SIG_KILL, we do
+         * a Ctrl+Break equiv which is more pleasant like the
+         * good old unix SIGTERM/HUP
+         */
+        if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) {
+            errno = ESRCH;
+            return -1;
+        }
+        break;
+
+    default:
+    {
+        HANDLE proc;
+        proc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
+        if (!proc) {
+            errno = ESRCH; /* Not entirely accurate, but close enough */
+            return -1;
+        }
+
+        /*
+         * TerminateProcess is more or less equiv to SIG_KILL, in that
+         * a process can't trap / block it
+         */
+        if (sig != 0 && !TerminateProcess(proc, sig)) {
+            errno = ESRCH;
+            return -1;
+        }
+        CloseHandle(proc);
+    }
+    }
+    return 0;
+#else
+    return kill(pid, sig);
+#endif
+}
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
new file mode 100644 (file)
index 0000000..b1000c6
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * virprocess.h: interaction with processes
+ *
+ * Copyright (C) 2010-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_PROCESS_H__
+# define __VIR_PROCESS_H__
+
+# include <sys/types.h>
+
+# include "internal.h"
+
+int virProcessKill(pid_t pid, int sig);
+
+#endif /* __VIR_PROCESS_H__ */