Solved

sending signal and handling in a shared library

Posted on 2012-03-30
3
536 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Notice: Undefined variable 5 56
linux crontab output 3 41
Xymon customize http timeout 2 32
cannot connect to openvpn server 9 18
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

15 Experts available now in Live!

Get 1:1 Help Now