public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yves Crespin <crespin.quartz@wanadoo.fr>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Yves Crespin <Crespin.Quartz@Wanadoo.fr>
Subject: sigwait() and 2.6
Date: Tue, 15 Feb 2005 13:58:28 +0100	[thread overview]
Message-ID: <4211F1F4.1070806@wanadoo.fr> (raw)
In-Reply-To: <1108471847.10281.3.camel@gaston>

[-- Attachment #1: Type: text/plain, Size: 3116 bytes --]

Hi,

Going on a 2.6 kernel, I have a trouble with sigwait()

When I send a kill to this program, the exit code is 143 (signal 15 and 
core)!

Is there a workaround ?

Thanks,

Yves

gcc -g -Wall -D_REENTRANT=1 -D_THREAD_SAFE=1 s.c -lpthread -o s

/===== début du code =====/

#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>

typedef    void Sigfunc(int);

#define ThreadBlockSignal()    ThreadSignalAction(SIG_BLOCK)
#define ThreadUnblockSignal()    ThreadSignalAction(SIG_UNBLOCK)

/*----------STATIC------------------*/
extern void ThreadSignalAction(const int how)
{
   sigset_t    newmask;

   if (sigemptyset(&newmask)<0){
       printf("sigemptyset failed");
       return;
   }
   if (sigaddset(&newmask,SIGTERM)<0){
       printf("sigaddset failed");
       return;
   }
   if (pthread_sigmask(how,&newmask,NULL)){
       printf("pthread_sigmask SIG_BLOCK failed");          return;
   }
}

extern Sigfunc * signal_intr(int signo,Sigfunc *func)
{
   struct sigaction    act, oact;

   act.sa_handler = func;
   sigemptyset(&act.sa_mask);
   act.sa_flags = 0;
   if (signo == SIGALRM){
#ifdef SA_INTERRUPT
       act.sa_flags |= SA_INTERRUPT;    /* Interrupt mode */
#endif /* SA_INTERRUPT */
   }else{
#ifdef SA_RESTART
       /*
        * automatic restart of interrupted system calls except
        * if they are operating on a slow device.
        * For select():
        * Under BSD, even if SA_RESTART is specified, select() was
        * never restarted.
        * Under SVR4, if SA_RESTART is specified, even select() and
        * pool() are automatically restarted.
        */
       act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
       if (signo == SIGCHLD){
           act.sa_flags |= SA_NOCLDSTOP; /* Don't send SIGCHLD when 
children stop*/
       }
   }

#ifdef SA_RESETHAND
   act.sa_flags &= ~SA_RESETHAND;    /* signal handle remains installed */
#endif /* SA_RESETHAND */
   if (sigaction(signo, &act, &oact) < 0){
       return(SIG_ERR);
   }
   return(oact.sa_handler);
}

extern int WaitSignal(void)
{
   sigset_t    newmask;
   int        ret;
   int        sig;

   if (sigemptyset(&newmask)<0){
       printf("sigemptyset failed");
       return -1;
   }
   if (sigaddset(&newmask,SIGTERM)<0){
       printf("sigaddset failed");
       return -1;
   }
   printf("Waiting signal ..."); fflush(stdout);
   ret = sigwait(&newmask,&sig);
   if (ret!=0){
       printf("WaitSignal: sigwait failed %d",ret);
   }else{
       printf("WaitSignal: sigwait sig %d",sig);
   }
   return sig;
}

int main(int argc,char * const argv[])
{
   if (signal_intr(SIGTERM,SIG_DFL) == SIG_ERR){
       printf("signal %d (set handle) failed",SIGTERM);
   }

   /* -- Main loop */
   printf("%lu ready ...",(unsigned long)getpid()); fflush(stdout);
       int    signo;

       ThreadUnblockSignal();
       signo = WaitSignal();
       ThreadBlockSignal();
       if (signo==SIGTERM){
           printf("\nSIGTERM in main\n"); fflush(stdout);
       }else{
           printf("\n%d in main\n",signo); fflush(stdout);
       }
   return 0;
}

/===== fin du code =====/


[-- Attachment #2: crespin.quartz.vcf --]
[-- Type: text/x-vcard, Size: 295 bytes --]

begin:vcard
fn:Yves Crespin
n:Crespin;Yves
org:Quartz
adr:Hameau du Pra - CIDEX 322;;39, rue Victor Hugo;CROLLES;;38920;France
email;internet:Crespin.Quartz@Wanadoo.fr
tel;work:04.76.92.21.91
tel;cell:06.86.42.86.81
x-mozilla-html:FALSE
url:http://crespin.quartz.free.fr/
version:2.1
end:vcard


  reply	other threads:[~2005-02-15 12:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3xVku-kH-15@gated-at.bofh.it>
2005-02-15  3:14 ` Radeon FB troubles with recent kernels Vincent C Jones
2005-02-15 12:46   ` Benjamin Herrenschmidt
2005-02-15 12:50   ` Benjamin Herrenschmidt
2005-02-15 12:58     ` Yves Crespin [this message]
2005-02-15 23:59       ` sigwait() and 2.6 Ulrich Drepper

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=4211F1F4.1070806@wanadoo.fr \
    --to=crespin.quartz@wanadoo.fr \
    --cc=linux-kernel@vger.kernel.org \
    /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