diff --git a/ffpb/ffpb-debug/files/bin/ffpb-debug b/ffpb/ffpb-debug/files/bin/ffpb-debug index 834a1e63a476696af8a6048d2319513edd80fd5c..a193d1f61241a2828752498c12a2681b67119324 100755 --- a/ffpb/ffpb-debug/files/bin/ffpb-debug +++ b/ffpb/ffpb-debug/files/bin/ffpb-debug @@ -2,6 +2,9 @@ debugdata = "" ATH9K_DEBUGFS_DIR="/sys/kernel/debug/ieee80211/phy0/ath9k" +PATH_DBG_REPORT='/tmp/debug-report.txt' + +local nixio = require('nixio'), require('nixio.util'), require('nixio.fs') -- wrapper for calling systemcommands function cmd(_command) @@ -40,9 +43,9 @@ if arg[1] == '-l' then localMode = true end --- search for existing debugreport.txt -local debugFile = io.open("/tmp/debugreport.txt", "r") -if debugFile==nil then +-- search for existing debug report +local oldReport = nixio.open(PATH_DBG_REPORT, "r") +if oldReport==nil then -- no existing debugreport, let's generate a new one -- inform the User ;) @@ -107,13 +110,10 @@ if debugFile==nil then os.execute("killall -USR1 fastd 2>/dev/null") debugdata = debugdata .. cmd("logread") debugdata = debugdata .. "---- END BATMAN AND FASTD STATUS ----\n\n" - - -- write debugreport to file - debugFile = io.open("/tmp/debugreport.txt", "w") - debugFile:write(debugdata) - debugFile:close() else print('I found an old debugreport.') + debugdata = oldReport:readall() + oldReport:close() end -- if local mode is requested print the report, otherwise send it to the admin team @@ -121,27 +121,42 @@ siteConfig = require("gluon.site_config") if localMode then print ('As requested, i will not send the report, here it is:') print (debugdata) - os.execute("rm /tmp/debugreport.txt") - os.exit(0) + nixio.fs.unlink(PATH_DBG_REPORT) else + local nixio = require('nixio'), require('nixio.util') print('Sending report to Admin-Team ...') - local reportSent = false + local sent = 0 + local reportname = nil local port = siteConfig.debugserver.port for host in list_iter(siteConfig.debugserver.host) do - print('Trying ' .. host) - if os.execute("cat /tmp/debugreport.txt | nc " .. host .. " " .. port) and reportSent == false then - reportSent = true + print('Trying to deliver debug-report to: ' .. host) + local sock = nixio.connect(host, port, "inet6", "stream") + if sock then + sock:setopt('socket', 'sndtimeo', 30.0) + sock:setopt('socket', 'rcvtimeo', 30.0) + sent = sock:writeall(debugdata) + if sent == debugdata:len() then + -- half-side close to indicate the end of our transmission + sock:shutdown('wr') + print('Transmission succeeded. Waiting for report-name.') + reportname = sock:readall(256) + end + sock:close() + if reportname ~= nil then break end end end - if reportSent then - print() - os.execute("rm /tmp/debugreport.txt") - print('Report was sent, the Adminteam has been informed.') - print('My job is done, good bye') + if reportname ~= nil then + print('\nYour report has been stored at the debug-server with the name: ' .. reportname) + print('I also notified some gurus to take care of the issue. My job is done here, good bye!.') else print('Sorry, i could\'t send the report. I will try it again') print('when this script will be invoked the next time.') print('Good bye') + local f = nixio.open(PATH_DBG_REPORT, 'w') + f:writeall(debugdata) + f:close() end end + +os.exit(0)