.\" -*-nroff-*- .\" .\" Manual for in-band signal handling .\" .\" (c) 1999, 2001, 2005, 2009, 2023, 2024 Straylight/Edgeware .\" . .\"----- Licensing notice --------------------------------------------------- .\" .\" This file is part of the mLib utilities library. .\" .\" mLib is free software: you can redistribute it and/or modify it under .\" the terms of the GNU Library General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or (at .\" your option) any later version. .\" .\" mLib is distributed in the hope that it will be useful, but WITHOUT .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public .\" License for more details. .\" .\" You should have received a copy of the GNU Library General Public .\" License along with mLib. If not, write to the Free Software .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, .\" USA. . .\"-------------------------------------------------------------------------- .so ../defs.man \" @@@PRE@@@ . .\"-------------------------------------------------------------------------- .TH sel 3mLib "23 July 1999" "Straylight/Edgeware" "mLib utilities library" .\" @sig_init .\" @sig_add .\" @sig_remove . .\"-------------------------------------------------------------------------- .SH NAME sig \- more controlled signal handling . .\"-------------------------------------------------------------------------- .SH SYNOPSIS . .nf .B "#include " .PP .B "typedef struct { ...\& } sig;" .PP .ta \w'\fBvoid sig_add('u .BI "void sig_add(sig *" s ", int " n , .BI " void (*" proc ")(int " n ", void *" p "), void *" p ); .BI "void sig_remove(sig *" s ); .BI "void sig_init(sel_state *" s ); .fi . .\"-------------------------------------------------------------------------- .SH "DESCRIPTION" . The .B sig subsystem uses the I/O multiplexing capabilities of .B mLib (see .BR sel (3) for details) to provide a more convenient interface for handling signals which don't need to be dealt with `right away'. Like the I/O system, .B sig doesn't allocate any memory for itself: you have to give it space to work in. .PP The system needs to be initialized before use. To do this, you must call .BR sig_init , passing it the address of an initialized multiplexor object. Signals handled through this interface will only be delivered when .BR sel_select (3) is called on that multiplexor. .PP To register interest in a signal, call .BR sig_add , passing it the following arguments: .TP .BI "sig *" s A pointer to an (uninitialized) object of type .BR sig . This will be used by the system to retain information about this signal claim. You use the address of this object to remove the handler again when you've finished. .TP .BI "int " n The number of the signal you want to handle. .PP .TP .BI "void (*" proc ")(int " n ", void *" p ) A function to call when the signal is detected. The function is passed the signal number and the pointer .I p passed to .BR sig_add . .TP .BI "void *" p A pointer argument to be passed to .I func when the signal is detected. .PP Removing a handler is easy. Call .B sig_remove with the address of the .B sig structure you passed to .BR sig_add . . .SS "Multiple signal handlers" You may have multiple signal handlers for a signal. All of them are called in some unspecified order when the signal occurs. .PP A signal's disposition is remembered when a handler for it is added and there are no handlers already registered. When the last handler for a signal is removed, its disposition is restored to its initial remembered state. . .\"-------------------------------------------------------------------------- .SH "BUGS AND CAVEATS" . The .B sig system attempts to set the .B SA_RESTART flag on signal handlers it creates that signal occurrences don't interrupt system calls. This won't be done on systems which don't define this flag, for obvious reasons. .PP The .B SA_NOCLDSTOP flag is also set, so that stopped child processes aren't reported by a signal. This is normally right, but ought to be configurable. . .\"-------------------------------------------------------------------------- .SH "SEE ALSO" . .BR signal (2), .BR sel (3), .BR mLib (3). . .\"-------------------------------------------------------------------------- .SH "AUTHOR" . Mark Wooding, . .\"----- That's all, folks --------------------------------------------------