linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Custom defined object in a signal handler
@ 2007-03-28 23:54 Sreevathsa
  2007-03-29  0:09 ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Sreevathsa @ 2007-03-28 23:54 UTC (permalink / raw)
  To: linux-c-programming

I have a question regarding signals. Is there a way you can pass some custom
defined parameter (say, a struct foo * ) to a signal handler??

To be more specific, struct sigaction defines 2 types of handlers - namely
sa_handler and sa_sigaction both of which have predefined set of arguments
to them.

sa_handler has (int) as the argument and sa_sigaction has (int, siginfo_t *,
void *) as its arguments. The third argument void * to sa_sigaction is for a
ucontext_t struct that contains the process's context at the time of signal
delivery.

My requirement is: I need to pass a struct foo * pointer to the signal
handler when I set it up and later when the signal is delivered I must be
able to see the foo * that I had passed at the time of setting up the
handler. Does anyone know how we can do this?

TIA,
Sreevathsa


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

* Re: Custom defined object in a signal handler
  2007-03-28 23:54 Custom defined object in a signal handler Sreevathsa
@ 2007-03-29  0:09 ` Glynn Clements
  2007-03-29  0:22   ` Sreevathsa
  0 siblings, 1 reply; 4+ messages in thread
From: Glynn Clements @ 2007-03-29  0:09 UTC (permalink / raw)
  To: Sreevathsa; +Cc: linux-c-programming


Sreevathsa wrote:

> I have a question regarding signals. Is there a way you can pass some custom
> defined parameter (say, a struct foo * ) to a signal handler??

No (other than by using a global variable).

As you can only install a single handler for any given signal, there
isn't any real need to support closures.

-- 
Glynn Clements <glynn@gclements.plus.com>

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

* RE: Custom defined object in a signal handler
  2007-03-29  0:09 ` Glynn Clements
@ 2007-03-29  0:22   ` Sreevathsa
  2007-03-29  3:21     ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Sreevathsa @ 2007-03-29  0:22 UTC (permalink / raw)
  To: 'Glynn Clements'; +Cc: linux-c-programming

I am working on a multithreaded application in which, in one of the code
paths, multiple threads need to setup a SIGALRM signal (to achieve TCP
retrasmission kind of functionality). When each thread does this, it also
need to pass the address of the structure that it operated upon, so that
when the signal is delivered, the signal handling thread will know the
address of the strucutre and can act upon it.

Is there any way to accomplish this goal? If you need any other info about
the problem environment, I can provide them, please let me know.

Thanks,
Sreevathsa

 

> -----Original Message-----
> From: linux-c-programming-owner@vger.kernel.org 
> [mailto:linux-c-programming-owner@vger.kernel.org] On Behalf 
> Of Glynn Clements
> Sent: Wednesday, March 28, 2007 5:09 PM
> To: Sreevathsa
> Cc: linux-c-programming@vger.kernel.org
> Subject: Re: Custom defined object in a signal handler
> 
> 
> Sreevathsa wrote:
> 
> > I have a question regarding signals. Is there a way you can 
> pass some 
> > custom defined parameter (say, a struct foo * ) to a signal 
> handler??
> 
> No (other than by using a global variable).
> 
> As you can only install a single handler for any given 
> signal, there isn't any real need to support closures.
> 
> --
> Glynn Clements <glynn@gclements.plus.com>
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in the body of a message to 
> majordomo@vger.kernel.org More majordomo info at  
> http://vger.kernel.org/majordomo-info.html


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

* RE: Custom defined object in a signal handler
  2007-03-29  0:22   ` Sreevathsa
@ 2007-03-29  3:21     ` Glynn Clements
  0 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2007-03-29  3:21 UTC (permalink / raw)
  To: Sreevathsa; +Cc: linux-c-programming


Sreevathsa wrote:

> I am working on a multithreaded application in which, in one of the code
> paths, multiple threads need to setup a SIGALRM signal (to achieve TCP
> retrasmission kind of functionality). When each thread does this, it also
> need to pass the address of the structure that it operated upon, so that
> when the signal is delivered, the signal handling thread will know the
> address of the strucutre and can act upon it.

Signal handlers are per-process, not per-thread; only the mask is
per-thread. Likewise for timers.

-- 
Glynn Clements <glynn@gclements.plus.com>

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

end of thread, other threads:[~2007-03-29  3:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-28 23:54 Custom defined object in a signal handler Sreevathsa
2007-03-29  0:09 ` Glynn Clements
2007-03-29  0:22   ` Sreevathsa
2007-03-29  3:21     ` Glynn Clements

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).