All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] Avoid dumping core in xen-detect
       [not found] <64b613c3664688602fa7.1260787336@dhcp-lab-164.englab.brq.redhat.com>
@ 2009-12-14 11:12 ` Keir Fraser
  2009-12-14 13:30   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Keir Fraser @ 2009-12-14 11:12 UTC (permalink / raw)
  To: Paolo Bonzini, xen-devel@lists.xensource.com

Much nicer, thanks!

 -- Keir

On 14/12/2009 11:08, "Paolo Bonzini" <pbonzini@redhat.com> wrote:

> From: pbonzini@redhat.com
> 
> # HG changeset patch
> # User Paolo Bonzini <pbonzini@redhat.com>
> # 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@redhat.com>
> 
> 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@lists.xensource.com
> http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Avoid dumping core in xen-detect
  2009-12-14 11:12 ` [PATCH] Avoid dumping core in xen-detect Keir Fraser
@ 2009-12-14 13:30   ` Paolo Bonzini
  2009-12-14 14:03     ` Keir Fraser
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2009-12-14 13:30 UTC (permalink / raw)
  To: xen-devel

On 12/14/2009 12:12 PM, Keir Fraser wrote:
> Much nicer, thanks!

Thanks, can you put this in the 3.4-testing tree too?

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH] Avoid dumping core in xen-detect
  2009-12-14 13:30   ` Paolo Bonzini
@ 2009-12-14 14:03     ` Keir Fraser
  0 siblings, 0 replies; 3+ messages in thread
From: Keir Fraser @ 2009-12-14 14:03 UTC (permalink / raw)
  To: Paolo Bonzini, xen-devel@lists.xensource.com

Will do.

 -- Keir

On 14/12/2009 13:30, "Paolo Bonzini" <pbonzini@redhat.com> wrote:

> On 12/14/2009 12:12 PM, Keir Fraser wrote:
>> Much nicer, thanks!
> 
> Thanks, can you put this in the 3.4-testing tree too?
> 
> Paolo
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-14 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <64b613c3664688602fa7.1260787336@dhcp-lab-164.englab.brq.redhat.com>
2009-12-14 11:12 ` [PATCH] Avoid dumping core in xen-detect Keir Fraser
2009-12-14 13:30   ` Paolo Bonzini
2009-12-14 14:03     ` Keir Fraser

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.