WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
To: pbonzini@xxxxxxxxxx
Subject: [Xen-devel] [PATCH] Avoid dumping core in xen-detect
From: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Date: Mon, 14 Dec 2009 12:08:49 +0100
Cc: pbonzini@xxxxxxxxxx
Delivery-date: Mon, 14 Dec 2009 03:09:12 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4
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

<Prev in Thread] Current Thread [Next in Thread>