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

[Xen-devel] [PATCH] Avoid dumping core in xen-detect



From: pbonzini@xxxxxxxxxx

# HG changeset patch
# User Paolo Bonzini <pbonzini@xxxxxxxxxx>
# Date 1260787292 -3600
# Node ID 64b613c3664688602fa726f0910ba4bc620cc577
# Parent  d44371e6e5d631f58d9a2ce829f12dafd1272f68
Avoid dumping core in xen-detect

F12 introduces a tool to automatically report bugs when there are core
dumps.  Since xen-detect relies on fork+waitpid in order to trap a SIGILL
from a child, every time someone runs xen-detect on a bare metal kernel
a bug is reported into Red Hat's Bugzilla. :-)

However, even without this contingent need, leaving core dumps around is
not nice.  So this patch just traps SIGILL using signal/sentjmp/longjmp,
without the need to fork.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>

diff --git a/tools/misc/xen-detect.c b/tools/misc/xen-detect.c
--- a/tools/misc/xen-detect.c
+++ b/tools/misc/xen-detect.c
@@ -29,9 +29,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/wait.h>
+#include <setjmp.h>
+#include <signal.h>
 #include <unistd.h>
 
+jmp_buf j;
 static int pv_context;
 
 static void cpuid(uint32_t idx,
@@ -74,6 +76,11 @@
     return 1;
 }
 
+void sigill_handler (int sig)
+{
+    longjmp(j, 1);
+}
+
 int main(void)
 {
     pid_t pid;
@@ -84,33 +91,18 @@
     if ( check_for_xen() )
         return 0;
 
-    /* Now we check for execution in PV context. */
-    pv_context = 1;
-
     /*
-     * Fork a child to test the paravirtualised CPUID instruction.
-     * If executed outside Xen PV context, the extended opcode will fault.
+     * Setup a signal handler to test the paravirtualised CPUID instruction.
+     * If executed outside Xen PV context, the extended opcode will fault
+     * and we'll print "Not running on Xen".
      */
-    pid = fork();
-    switch ( pid )
-    {
-    case 0:
-        /* Child: test paravirtualised CPUID opcode and then exit cleanly. */
-        cpuid(0x40000000, &dummy, &dummy, &dummy, &dummy);
-        exit(0);
-    case -1:
-        fprintf(stderr, "Fork failed.\n");
-        return 0;
+    signal(SIGILL, sigill_handler);
+    if (setjmp(j) == 0) {
+        pv_context = 1;
+        if ( check_for_xen() )
+            return 0;
     }
 
-    /*
-     * Parent waits for child to terminate and checks for clean exit.
-     * Only if the exit is clean is it safe for us to try the extended CPUID.
-     */
-    waitpid(pid, &status, 0);
-    if ( WIFEXITED(status) && check_for_xen() )
-        return 0;
-
     printf("Not running on Xen.\n");
     return 0;
 }



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.