I’m developping AGI program by C.
I want to execute some function (remove tempolary files, dispatch logs etc.) when AGI program exits.
I tried atexit(3), but registered function was not executed.
Are there any ways to execute function at AGI exit?
You should be asking this question as:
A method for performing cleanup operations just before execution ends for a program written in C.
Moving on …
You have to built this functionality in the C code.
I mean you should return from functions to the called functions after exceution of the functionalities. In the end you return to main where you
can call the cleanup operation before execution stops.
Or
You can use C++ and created an object whose destructor will be called automatically when the main terminates.
In the case when the AGI program exits by itself, I can call cleanup operations.
In another case when the call is hanged up by phone caller, also I want to execute cleanup operations.
I think it is able to detect hang-up by using AGI get_data.
But, at the timing get_data is not call, are there any method to detect the hang-up?
I found following description in res_agi.c (asterisk-1.4.0-beta3).
…
" A locally executed AGI script will receive SIGHUP on hangup from the cha nnel\n"
“except when using DeadAGI. This can be disabled by setting the AGISIGHUP channel\n”
“variable to “no” before executing the AGI application.\n”
…
It seems to be able to detect hang-up in AGI process by catching SIGHUP.
Now I don’t have environment to run asterisk-1.4.0. I’ll try later.
In 1.2.* there is no AGISIGHUP and no explicit specification in the
description.
static char *descrip =
" [E|Dead]AGI(command|args): Executes an Asterisk Gateway Interface compliant\n"
"program on a channel. AGI allows Asterisk to launch external programs\n"
"written in any language to control a telephony channel, play audio,\n"
"read DTMF digits, etc. by communicating with the AGI protocol on stdin\n"
"and stdout.\n"
"Returns -1 on hangup (except for DeadAGI) or if application requested\n"
" hangup, or 0 on non-hangup exit. \n"
"Using 'EAGI' provides enhanced AGI, with incoming audio available out of band\n"
"on file descriptor 3\n\n"
"Use the CLI command 'show agi' to list available agi commands\n";
But the run_agi does calls
kill(pid, SIGHUP);
whereas in 1.4.* the call depends on value of AGISIGHUP.