LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-01-2004, 05:18 AM   #1
igor.kopriva
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Rep: Reputation: 0
how to detect that I'm handling signal


Hi all,
I need to detect that function has been called during signal handling. In other words, there is signal handler installed. Inside handler is called function A(). In normal code, outside singal handler, the A() is called as well. The A() function contains code which is not possible to use in signal handler, so I need to detect that A() was called in signal handler context.

It is of course impossible to pass information whether signal is handled as a parameter. It is also impossible to differ A() function into two kinds, one for signals and one for normal context. In fact the A() function is injected into running code image.

Thanx in advance,
Igor Kopriva
 
Old 10-01-2004, 05:32 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
You haven't specified a programming language; my signal experience is mostly through Perl but I suspect it'll be transferable to whatever you are using, or someone will say if not.

At least in Perl, it's bad practice to call a function from within a signal handler, as it begs the question of what happens if another signal arrives during the processing of the first signal. It's better to set a flag (a static or global variable) within the signal handler and then poll this flag to see if it's been set, calling the function from outside if necessary, then setting the flag to cleared after the function returns (or just before you call it if you want to allow the signal handler function to be interrupted by signals).

If you used a global variable as the flag, then you can test it to see if it's set or not to find out if you're in signal handler mode. There's one too many global variables in that approach, but I don't see why it wouldn't work.
 
Old 10-01-2004, 05:46 AM   #3
igor.kopriva
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Original Poster
Rep: Reputation: 0
more precise

I am programming in ANSI C.

It is impossible to modify anything in signal handler at all. The function A() acts as the notify function for function patching. In fact the A() is injected into the running code at the place where patched function B() is called. It means that A() is called instead of B(). It is modification in RAM during execution, so no modification to source of signal handler is allowed. It's a very tricky part of code written in assembler. Because there are mutexes and so on to protect it in multithread environment, it hangs when user decides to patch somethin called within signal context. That's why I need to detect if i am in signal context or not.

Thanx Igor
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads in signal handling shilpig Programming 3 08-20-2009 03:14 AM
Signal handling......... rajsun Programming 2 06-28-2005 08:10 AM
Signal handling from bash shy Programming 2 11-20-2004 08:41 AM
Signal Handling with LinuxThrreads TedMaul Programming 1 05-01-2004 01:56 PM
Signal handling Mohsen Programming 2 07-30-2003 06:55 AM


All times are GMT -5. The time now is 05:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration