[Freeswitch-users] hook to event or startup script which will hook to events?

Mimiko vbvbrj at gmail.com
Sun Feb 7 17:59:42 MSK 2016


Hello.

I'm running FS without problems for 3 years. I installed back then FS 
version 1.3.13b cad607d72e and it is running till now. I know it is old, 
but its stable.

Back then I've used a start-up script in lua to catch callcenter's 
events and populate DB. Script is started and hooked to callcenter 
events. Now I want to add a event parse script for RECORD_STOP event. 
I've seen in lua.conf that I can use

<hook event="RECORD_STOP" script="script.lua"/>

to autohook and execute script for every RECORD_STOP event. For testing 
I've write a small script to just log info:

scriptname=argv[0]
freeswitch.consoleLog("notice", scriptname.." Starting...\n")
isdebug=false
min_rec_secs=0 -- In seconds.
api = freeswitch.API()
recordings_dir = api:execute("global_getvar", "recordings_dir")
databasename = api:execute("global_getvar", "freeswitch_data_db")
databaseuser = api:execute("global_getvar", "freeswitch_databaseuser")
databasepass = api:execute("global_getvar", "freeswitch_databasepass")
function printlog (a,...)
	-- First paramter - line number
	-- Second parameter - lvl=debug,info,notice,warning,err,crit,alert
	-- Third parameter - the message
	-- Calling: printlog([line number,][log lvl,]message)
	local arg={...}
	line=0
	lvl="debug"
	msg=a
	if (type(a)=='number' and a>0) then line=a else line=0 end
	maybe_lvl=string.lower(a)
	if (maybe_lvl=="debug" or maybe_lvl=="info" or maybe_lvl=="notice" or 
maybe_lvl=="warning" or maybe_lvl=="err" or maybe_lvl=="crit" or 
maybe_lvl=="alert") then
		lvl=maybe_lvl
	elseif (#arg>=1) then
		maybe_lvl=string.lower(arg[1])
		if (maybe_lvl=="debug" or maybe_lvl=="info" or maybe_lvl=="notice" or 
maybe_lvl=="warning" or maybe_lvl=="err" or maybe_lvl=="crit" or 
maybe_lvl=="alert") then
			lvl=maybe_lvl
		end
	end
	if (#arg==1) then msg=arg[1] end
	if (#arg==2) then msg=arg[2] end
	if not (isdebug and lvl=="debug") then 
freeswitch.consoleLog(lvl,scriptname .. " (" .. line .."): " .. msg .. 
"\n") end
end--]]
freeswitch.consoleLog("notice", scriptname..event:serialize("").."\n")

After restarint FS it is working and event variables are printed.

But after a while (several hours of working) FS segfaults to this:

kernel: [13834853.520624] freeswitch[31414]: segfault at 7f5b05178ca0 ip 
00007f5b08100f32 sp 00007f5ae7d32d38 error 4 in 
libc-2.11.3.so[7f5b08085000+159000]

If I comment <hook event="RECORD_STOP" script="script.lua"/>, then FS 
runs ok without segfaults.

My questions:

1) What is the better way to parse events: using start-up script which 
will hook to events and waits for them, or hook script to event in 
lua.conf and run the script only when event arise?

2) Why it segfaults on this script? Same code (function and getting 
variables) in other scripts, started from dialplan, does not segfault FS.

3) Was this a known bug and latest stable version will resolve the 
problem? I would not want to upgrade if the problem will remain.

Thank you.

-- 
Mimiko desu.



Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list