Solved

sending signal and handling in a shared library

Posted on 2012-03-30
3
635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

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 35

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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

617 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