[PATCH] virprocess: make virProcessGetStartTime work on Mac OS X

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

 



This patch addresses the following warning output by libvirtd:
  warning : virProcessGetStartTime:843 : Process start time of
  pid XXXXX not available on this platform

For Mac OS X, we can use similar instructions to FreeBSD
to get the start time of a process. The difference between them
is struct kinfo_proc; kinfo_proc.ki_start is the start time
of a process for FreeBSD while kinfo_proc.kp_proc.p_starttime
for Mac OS X.

Note that this patch works for Lion and Mountain Lion, however,
doesn't work for Snow Leopard for some reason;
sysctlnametomib("kern.proc.pid", ...) fails on Snow Leopard with
the following error:
  error : virProcessGetStartTime:822 : Unable to get MIB of
  kern.proc.pid: No such file or directory

This is unexpected. man 3 sysctl of Snow Leopard says it
should work...

Anyway libvirtd is able to launch on Snow Leopard regardless of
the error.

Signed-off-by: Ryota Ozaki <ozaki.ryota@xxxxxxxxx>
---
 src/util/virprocess.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9fc3207..5a0ed0d 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -32,7 +32,7 @@
 #endif
 #include <sched.h>
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
 # include <sys/param.h>
 # include <sys/sysctl.h>
 # include <sys/user.h>
@@ -809,7 +809,7 @@ cleanup:
     VIR_FREE(buf);
     return ret;
 }
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__APPLE__)
 int virProcessGetStartTime(pid_t pid,
                            unsigned long long *timestamp)
 {
@@ -817,7 +817,12 @@ int virProcessGetStartTime(pid_t pid,
     int mib[4];
     size_t len = 4;
 
-    sysctlnametomib("kern.proc.pid", mib, &len);
+    /* FIXME: It doesn't work on Snow Leopard for some reason */
+    if (sysctlnametomib("kern.proc.pid", mib, &len) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to get MIB of kern.proc.pid"));
+        return -1;
+    }
 
     len = sizeof(struct kinfo_proc);
     mib[3] = pid;
@@ -828,7 +833,11 @@ int virProcessGetStartTime(pid_t pid,
         return -1;
     }
 
+# if defined(__FreeBSD__)
     *timestamp = (unsigned long long)p.ki_start.tv_sec;
+# else
+    *timestamp = (unsigned long long)p.kp_proc.p_starttime.tv_sec;
+# endif
 
     return 0;
 
-- 
1.8.4

--
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]