From b4aa1a9746cadb616652482e260e0a87c4d32a53 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Tue, 23 Feb 2016 16:18:42 +0100 Subject: [PATCH] Wifibox stdout/stderr log file: - rename 'wifibox.cgi-fallback.log' to 'wifibox.stdout.log' - extend description of Lua debugging (and the fallback log) - send fallback log along with info/logfiles request --- README.md | 8 ++++++-- src/conf_defaults.lua | 2 +- src/rest/api/api_info.lua | 5 +++++ src/script/d3dapi | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5e1513d..5638ba3 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ WiFi box OpenWRT firmware package General documentation can be found on the wiki: . Source code documentation can be generated, see below. + Documentation ------------- @@ -19,5 +20,8 @@ Syntax errors in Lua can lead to tricky issues since they might only surface whe One countermeasure for this is to use [pcall](http://www.lua.org/pil/8.4.html) instead of regular calls in many cases. To let the error 'happen' (which in turn gives information in the form of stack traces), tell the code to use regular calls by setting 'M.DEBUG_PCALLS' to 'true' in `conf_defaults.lua`. -A second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'. -Be aware though, that this script redirects output streams to a fallback log file where stack traces will end up, this file is `/tmp/wifibox.cgi-fallback.log`. +Additionally, when the pcall setting is not enough, a second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'. + +Note that because stack traces are sent to `stderr`, this script redirects output streams to a separate log file: `/tmp/wifibox.stdout.log`; apart from these traces, the file should not contain any data. + +Finally, the `CGI` gateway of uhttpd also uses this script, so the API can also be used to obtain stack traces by calling it as `/cgi-bin/d3dapi/` (note the extra `cgi-bin`). diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index 5dd9093..95f5113 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -36,7 +36,7 @@ M.DEBUG_PCALLS = false --- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests. -- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`. --- Note that the command-line script redirects the output streams to '/tmp/wifibox.cgi-fallback.log' +-- Note that the command-line script redirects the output streams to '/tmp/wifibox.stdout.log', -- meaning that any stack traces can be found there. M.DEBUG_API = true diff --git a/src/rest/api/api_info.lua b/src/rest/api/api_info.lua index 5e07d37..f5283c1 100644 --- a/src/rest/api/api_info.lua +++ b/src/rest/api/api_info.lua @@ -21,6 +21,8 @@ local LOG_COLLECT_DIRNAME = 'wifibox-logs' local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME local DEFAULT_WIFIBOX_LOG_FILENAME = 'wifibox.log' local DEFAULT_WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. DEFAULT_WIFIBOX_LOG_FILENAME +local WIFIBOX_STDOUT_LOG_FILENAME = 'wifibox.stdout.log' +local WIFIBOX_STDOUT_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME local MOD_ABBR = "AINF" local SYSLOG_FILENAME = 'syslog' @@ -73,6 +75,9 @@ function M.logfiles(request, response) -- copy wifibox API-script log rv,sig,code = redirectedExecute('cp ' .. wifiboxLogFilePath .. ' ' .. LOG_COLLECT_DIR) + -- copy d3dapi script stdout/stderr log + rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_STDOUT_LOG_FILE .. ' ' .. LOG_COLLECT_DIR) + -- capture syslog rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME) diff --git a/src/script/d3dapi b/src/script/d3dapi index c97fab5..948c22f 100644 --- a/src/script/d3dapi +++ b/src/script/d3dapi @@ -10,7 +10,7 @@ LUA=lua SCRIPT_PATH=/usr/share/lua/wifibox -LOG_FILE=/tmp/wifibox.cgi-fallback.log +LOG_FILE=/tmp/wifibox.stdout.log cd $SCRIPT_PATH #echo "CGI invocation" >> $LOG_FILE