I have a possible "It Can't Be Done!" problem, which I'd like to bounce off the community.
I'm working the libIPFIX program, written in C. At the start of the code, the program sets up a Signal Handler function:
void exit_func ( int signo )
{
if ( verbose_level && signo )
fprintf( stderr, "\n[%s] got signo %d, bye.\n\n", progname, signo );
...clean up global variables...
exit( 1 );
}
Later in main(), the signal handler is wired into the larger code:
int main (int argc, char *argv[])
{
...
// signal handler
signal( SIGKILL, exit_func );
signal( SIGTERM, exit_func );
signal( SIGINT, exit_func );
...
exit(1);
}
Pretty boilerplate, from what I can tell.
Here's my issue: I'm tracking a lot of extra data in my modified version of the program, using malloc() and linked lists and whatnot. When the code detects a signal, it would be great if exit_func()
could call my cleanup() functions to eliminate memory leaks, blah blah blah. What I'd love is this:
void exit_func ( int signo, LLNode* myData )
{
...same...
cleanUp( myData );
exit( 1 );
}
But a reading of sigaction plus posts like these plus my own experimenting strongly suggest that there isn't a way to pass in an additional argument to exit_func()
. And that the only way to do what I want is to make my data into a global variable. I'd really hate to do that for other design reasons.
So I thought I'd go for broke and just ask: Is there was way to pass an argument into exit_func()
? Thanks in advance.