• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Missing in sigaction
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Missing in sigaction


  • Subject: Re: Missing in sigaction
  • From: Nat! <email@hidden>
  • Date: Wed, 28 Mar 2012 00:50:49 +0200

Am 27.03.2012 um 22:22 schrieb Tilghman Lesher:

> On Tue, Mar 27, 2012 at 1:57 PM, Nat! <email@hidden> wrote:
>> instead of many words, here's the output of two program runs once with a sleep( 2) - as in seconds, not as in man -  commented in and out. What I believe this demonstrates, is that on Darwin (Kernel Version 10.8.0), blocked signal information is lost, which is incovenient. gdb has a similiar problem.
>>
>> Or it shows that I am misunderstanding something ;)
>>
>> The problem is not that the signal is occurring less often, that's expected, but that the struct __siginfo has trouble remembering things.
>
> You really should read the manpage for sigaction, in particular, the
> section that reads:
>
> "In general though, signal handlers should do little more than set a
> flag; most other actions are not safe."
>
> Note, also, that printf() is not in the list of "safe" functions to
> call.  Thus your call to p_log is defined as not safe.  While sleep()
> is safe to call, it also violates one of the cardinal rules of signal
> handlers -- do only what is necessary to flag that a signal occurred,
> and do not take more time than is necessary.  The actual handling of
> what the signal represents should be done in a main thread.
>
> -Tilghman
>


Tilghman, do you really think printf will magically erase struct __siginfo.si_pid ahead of printf even being called ?

To make you feel better, appended is the same code, without printf, "surprisingly" with the same result.

Ciao
   Nat!


#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


static void  p_log( char *s)
{
   printf( "%d: %s\n", getpid(), s);
}


static struct __siginfo   memo;


static void  signal_action( int signal, struct __siginfo *info, void *data)
{
   memo = *info;

   /// COMMENT-UNCOMMENT ///
   sleep( 2);
}


static void   _test( void)
{
   p_log( "fork");
   if( ! fork())
   {
      p_log( "kill");
      kill( getppid(), SIGUSR1);
      p_log( "sleep");
      sleep( 1);
      p_log( "kill");
      kill( getppid(), SIGUSR1);
      p_log( "sleep");
      sleep( 1);
      p_log( "_exit");
      _exit( 0);
   }
}


int   main( int argc, char *argv[])
{
   struct sigaction   act;
   int                status;

   sigemptyset( &act.sa_mask);
   act.__sigaction_u.__sa_sigaction = signal_action;
   act.sa_flags = SA_SIGINFO|SA_RESTART;

   p_log( "sigaction");
   sigaction( SIGUSR1, &act, NULL);

   _test();
   _test();

   p_log( "wait");
   while( wait( &status) == -1);
   p_log( "wait");
   while( wait( &status) == -1);

   printf( "%d: memo = { %d, %d, %d, %d }\n", getpid(), memo.si_signo,  memo.si_errno,  memo.si_code,  memo.si_pid);

   p_log( "_exit");
   _exit( 0);
}


---------------------------------------------------
I learned that a cynic is the name given to people,
who know what’s coming by people who don’t, and
have regarded it as a compliment ever since.
   -- J. Watkinson



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Missing in sigaction
      • From: Tilghman Lesher <email@hidden>
    • Re: Missing in sigaction
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >Missing in sigaction (From: Nat! <email@hidden>)
 >Re: Missing in sigaction (From: Tilghman Lesher <email@hidden>)

  • Prev by Date: Re: Missing in sigaction
  • Next by Date: Re: Missing in sigaction
  • Previous by thread: Re: Missing in sigaction
  • Next by thread: Re: Missing in sigaction
  • Index(es):
    • Date
    • Thread