Solved

sending signal and handling in a shared library

Posted on 2012-03-30
3
546 Views
Last Modified: 2012-04-25
Hi Experts,

I am working on a shared library to provide some functionality.  I want to be able to set some attributes when this library is loaded and running in a process.  For example, I want to set the log level of my library based on some signals.  For example,  when the user wants to change the log level, he can change some attributes and notify the process somehow.  How can I detect this signal.  I am working on Linux.
0
Comment
Question by:ambuli
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 37792074
The common practice is to use SIGHUP to notify a process that it should re-read its configuration file. See for instance man 8 init(although init also has telinit q as an alternative).
Since they are asynchronous events, signals are inherently tricky to handle. However the API to handle them has improved over the years. Don't even think of using the original ANSI signal() function: here's what it's man page has to say
The behavior of signal() varies across UNIX versions, and has also varied historically across different versions of Linux.  Avoid its use: use sigaction(2) instead.  See Portability below.
So you are going to use sigaction() to declare your signal handling function (signal handler). You will notice from its man page that the handler can be declared as either an sa_handler() or an sa_sigaction(). Although it looks more complicated, sa_sigaction() is the portable one and I strongly recommend it.
As a general rule, the less a signal handler does, the better. This reduces the effort that has to be expended to deal with the possible  arrival of another (possibly different) signal while the signal handler is executing. What I'm saying here is that it would be ideal if you could have your signal handler simply set a flag (that a signal has been received), and that code which depends on the configuration should re-read it and clear the flag (when the flag is set).
You can re-read the configuration inside the signal handler, but this could lead to unexpected results (e.g. a piece of code that depends on 2 different config items might process one old and one new value).
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 37792085
Being in a shared library makes no difference, except the application should not use the same signal and nor should any other libraries it loads.
0
 

Author Comment

by:ambuli
ID: 37792192
Thank you very much hope for the good explanation. Much appreciated.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cannot connect to openvpn server 9 58
php ssh2_scp_send 1 46
Why isn't object file created? 6 39
Linux Copy Command - All Files inc Directory 1 23
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now