qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Riku Voipio <riku.voipio@iki.fi>
To: Thiemo Seufer <ths@networkno.de>
Cc: qemu-devel@nongnu.org, lauro.venancio@openbossa.org
Subject: Re: [Qemu-devel] [PATCH] linux-user: Proper exit code for uncaught signals
Date: Thu, 27 Nov 2008 14:21:44 +0200	[thread overview]
Message-ID: <20081127122144.GA5905@kos.to> (raw)
In-Reply-To: <20081127114233.GC15592@networkno.de>

On Thu, Nov 27, 2008 at 12:42:33PM +0100, Thiemo Seufer wrote:
> Riku Voipio wrote:
> > The proper exit code for dieing from an uncaught signal is -<signal>.
> > The kernel doesn't allow exit() or _exit() to pass a negative value.
> > To get the proper exit code we need to actually die from an uncaught
> > signal.
> > 
> > A default signal handler is installed, we send ourself a signal
> > and we wait for it to arrive.
> > 
> > Patch originates from Scratchbox
> 
> So, who holds the copyright (and deserves the credit)?

The qemu tarball[1] provided on scratchbox site doesn't
document who wrote patches and who has the copyright. Most
likely a contractor for Nokia wrote it, and the copyright is
Nokia's.

Lauro might know as the patch is also at the qemu-arm-eabi
sf project site.

[1] http://scratchbox.org/download/files/sbox-releases/stable/src/scratchbox-devkit-cputransp-qemu-arm-cvs-m-1.0.7/qemu-arm-0108.tar.gz

> Thiemo
> 
> > Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
> > ---
> >  linux-user/signal.c |   37 +++++++++++++++++++++++++------------
> >  1 files changed, 25 insertions(+), 12 deletions(-)
> > 
> > diff --git a/linux-user/signal.c b/linux-user/signal.c
> > index e0f6aaf..dac9933 100644
> > --- a/linux-user/signal.c
> > +++ b/linux-user/signal.c
> > @@ -24,6 +24,7 @@
> >  #include <unistd.h>
> >  #include <signal.h>
> >  #include <errno.h>
> > +#include <assert.h>
> >  #include <sys/ucontext.h>
> >  
> >  #include "qemu.h"
> > @@ -328,21 +329,33 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q)
> >  static void __attribute((noreturn)) force_sig(int sig)
> >  {
> >      int host_sig;
> > +    struct sigaction act;
> >      host_sig = target_to_host_signal(sig);
> >      fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
> >              sig, strsignal(host_sig));
> > -#if 1
> > -    _exit(-host_sig);
> > -#else
> > -    {
> > -        struct sigaction act;
> > -        sigemptyset(&act.sa_mask);
> > -        act.sa_flags = SA_SIGINFO;
> > -        act.sa_sigaction = SIG_DFL;
> > -        sigaction(SIGABRT, &act, NULL);
> > -        abort();
> > -    }
> > -#endif
> > +
> > +    /* The proper exit code for dieing from an uncaught signal is
> > +     * -<signal>.  The kernel doesn't allow exit() or _exit() to pass
> > +     * a negative value.  To get the proper exit code we need to
> > +     * actually die from an uncaught signal.  Here the default signal
> > +     * handler is installed, we send ourself a signal and we wait for
> > +     * it to arrive. */
> > +    sigfillset(&act.sa_mask);
> > +    act.sa_handler = SIG_DFL;
> > +    sigaction(host_sig, &act, NULL);
> > +
> > +    /* For some reason raise(host_sig) doesn't send the signal when
> > +     * statically linked on x86-64. */
> > +    kill(getpid(), host_sig);
> > +
> > +    /* Make sure the signal isn't masked (just reuse the mask inside
> > +    of act) */
> > +    sigdelset(&act.sa_mask, host_sig);
> > +    sigsuspend(&act.sa_mask);
> > +
> > +    /* unreachable */
> > +    assert(0);
> > +
> >  }
> >  
> >  /* queue a signal so that it will be send to the virtual CPU as soon
> > -- 
> > 1.5.6.5
> > 
> > 
> > -- 
> > "rm -rf" only sounds scary if you don't have backups
> > 

-- 
"rm -rf" only sounds scary if you don't have backups

      parent reply	other threads:[~2008-11-27 12:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-23 21:37 [Qemu-devel] [PATCH] linux-user: Proper exit code for uncaught signals Riku Voipio
2008-11-27 11:42 ` Thiemo Seufer
2008-11-27 12:16   ` Jamie Lokier
2008-11-27 12:44     ` Riku Voipio
2008-11-27 12:21   ` Riku Voipio [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081127122144.GA5905@kos.to \
    --to=riku.voipio@iki.fi \
    --cc=lauro.venancio@openbossa.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ths@networkno.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).