]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Move virProcessKill into virprocess.{h,c}
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 24 Sep 2012 16:54:51 +0000 (17:54 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 26 Sep 2012 09:09:57 +0000 (10:09 +0100)
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>
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 4ae741be274ec4cc5ed9f3820282b5ca3967cf65..ae3d491cadca2e98cb2c1848ea2f2d5796b715d8 100644 (file)
@@ -87,6 +87,7 @@ UTIL_SOURCES =                                                        \
                util/virnodesuspend.c util/virnodesuspend.h     \
                util/virobject.c util/virobject.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 4bb6fa349291692b231934d7236efc05e634ad7d..52c2cb23be3950afe04f4c0112c786bf3034a026 100644 (file)
@@ -1708,6 +1708,9 @@ virPidFileDelete;
 virPidFileDeletePath;
 
 
+# virprocess.h
+virProcessKill;
+
 # virrandom.h
 virRandom;
 virRandomBits;
index 2eae3f2a07f1db5019fb1463b0bfdd2b4b625ab5..ab6dc2238e5c9805861de4a1cd4ea23f0ab2a920 100644 (file)
@@ -39,6 +39,7 @@
 #include "virterror_internal.h"
 #include "json.h"
 #include "virfile.h"
+#include "virprocess.h"
 #include "virtime.h"
 #include "virobject.h"
 
index aec7b6c5111ec25ee3f6f485d30251fd5a70655d..2796a613dc795b5f98c27724afe0274be2f945b5 100644 (file)
@@ -36,6 +36,7 @@
 #include "memory.h"
 #include "logging.h"
 #include "virfile.h"
+#include "virprocess.h"
 #include "virobject.h"
 
 #ifdef WITH_DTRACE_PROBES
index 637f7be5cb102368c6220dcc3d472932ccf1c1db..3cd30afb79cf6922a93ce87dc00f01d00feed559 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"
 #include "bitmap.h"
index 6d0ef7907b92a40440875cf8cab658ecf9c01c7f..c341fabeb9f6c96494f68f4f3ac3d517585d4f8c 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 5bf82dc2f3b7750ada306004af70938db1060bb9..062fbf8a93cff435a5aff2f57e2e006e6f6e5632 100644 (file)
@@ -2289,63 +2289,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 501373d1aba7d10d5036933de660c7a909fea27a..5ab36ed35c00cdbf2a31708a9bc2d194b3d5d748 100644 (file)
@@ -255,8 +255,6 @@ static inline int getgid (void) { return 0; }
 
 char *virGetHostname(virConnectPtr conn);
 
-int virProcessKill(pid_t pid, int sig);
-
 char *virGetUserDirectory(void);
 char *virGetUserConfigDirectory(void);
 char *virGetUserCacheDirectory(void);
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__ */