[Nagios-devel] [RFC] Missing signal handling in ndo2db

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] [RFC] Missing signal handling in ndo2db

Post by Guest »

This is a multi-part message in MIME format.
--------------020902060807010101060807
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi List,

regarding the flat ndo2db init script with it's tough "killall
ndo2db..." I reviewed the signal processing in ndo2db.

Intro:
As we know ndo2db forks first to become a daemon, no problem up to here,
and forks again for each client connection.
Each client connection has the daemon as session leader but if we send
this leader a SIGTERM the parent process is exiting, deleting the
socket, cleaning up and 'over and out'.
Bad thing: The forked connection child is still alive, hanging around in
read() from the (non existing) socket descriptor.

Possible Solution:
kill(0,sig);

kill(0,SIGNAL) should send the SIGNAL to the complete process group, the
childs do already recognize SIGTERM resulting in _exit(0).
The existing parent sighandler for SIGCHLD does a waitpid for the childs
and in my opinion the world is nice so far.

I already tested the attached patch and it's working fine so far, I just
want to see if there are better ways to handling those parent/child signals.

Regards,
Hendrik
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpLMbgACgkQlI0PwfxLQjlwPQCeKBoR0TMhVHhCp2OsO8huUpQ6
27sAn1RysNAs4fdMjhV0prlS60Nr9ExO
=uYBW
-----END PGP SIGNATURE-----

--------------020902060807010101060807
Content-Type: text/x-patch;
name="ndo2db-fix-child-signals.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ndo2db-fix-child-signals.patch"

--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -708,11 +708,19 @@ int ndo2db_cleanup_socket(void){

void ndo2db_parent_sighandler(int sig){

- /* cleanup children that exit, so we don't have zombies */
- if(sig==SIGCHLD){
- while (waitpid(-1, NULL, WNOHANG) > 0);
+ switch (sig){
+ case SIGTERM:
+ /* forward signal to all members of this group of processes */
+ kill(0, sig);
+ break;
+ case SIGCHLD:
+ /* cleanup children that exit, so we don't have zombies */
+ while(waitpid(-1,NULL,WNOHANG)>0);
return;
- }
+
+ default:
+ printf("Caught the Signal '%d' but don't care about this.\n", sig);
+ }


--------------020902060807010101060807--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked