Author: titmuss
Date: Thu Feb 7 07:19:18 2008
New Revision: 1848
URL: http://svn.slimdevices.com?rev=1848&root=Jive&view=rev
Log:
[EMAIL PROTECTED] (orig r1842): titmuss | 2008-02-07 13:09:05 +0000
Bug: 6580
Description:
Fix jive application to not crash when wpa_supplicant is restarted (this will
happen
during suspend/resume).
Modified:
trunk/ (props changed)
trunk/jive/src/pkg/jive/share/jive/ui/Task.lua
trunk/jive/src/pkg/jive_squeezeboxjive/share/jive/net/Wireless.lua
trunk/jive/src/pkg/jive_squeezeboxjive/src/jive_wireless.c
Propchange: trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Thu Feb 7 07:19:18 2008
@@ -1,3 +1,3 @@
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1838
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1842
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378
Modified: trunk/jive/src/pkg/jive/share/jive/ui/Task.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/ui/Task.lua?rev=1848&root=Jive&r1=1847&r2=1848&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/ui/Task.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/ui/Task.lua Thu Feb 7 07:19:18 2008
@@ -94,7 +94,7 @@
log:debug("addTask ", self.name)
if self.state == "error" then
- log:warn("task has error")
+ log:warn("task ", self.name, " in error state")
return false
end
Modified: trunk/jive/src/pkg/jive_squeezeboxjive/share/jive/net/Wireless.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive_squeezeboxjive/share/jive/net/Wireless.lua?rev=1848&root=Jive&r1=1847&r2=1848&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive_squeezeboxjive/share/jive/net/Wireless.lua
(original)
+++ trunk/jive/src/pkg/jive_squeezeboxjive/share/jive/net/Wireless.lua Thu Feb
7 07:19:18 2008
@@ -71,8 +71,7 @@
obj.interface = interface
obj.responseQueue = {}
- obj.t_sock = wireless:open()
- obj:_addPump()
+ obj:open()
_instance[interface] = obj
return obj
@@ -171,12 +170,22 @@
function t_scan(self, callback)
assert(Task:running(), "Wireless:scan must be called in a Task")
- self:request("SCAN")
-
- local status = self:request("STATUS")
+ local status, err = self:request("SCAN")
+ if err then
+ return
+ end
+
+ local status, err = self:request("STATUS")
+ if err then
+ return
+ end
+
local associated = string.match(status, "\nssid=([^\n]+)")
- local scanResults = self:request("SCAN_RESULTS")
+ local scanResults, err = self:request("SCAN_RESULTS")
+ if err then
+ return
+ end
_scanResults = _scanResults or {}
@@ -527,7 +536,21 @@
end
-function _addPump(self)
+function open(self)
+ if self.t_sock then
+ log:error("Socket already open")
+ return
+ end
+
+ local err
+ self.t_sock, err = wireless:open()
+ if err then
+ log:warn(err)
+
+ self:close()
+ return false
+ end
+
local source = function()
return self.t_sock:receive()
end
@@ -552,9 +575,26 @@
self:t_addRead(function()
-- XXXX handle timeout
- return ltn12.pump.step(source, sink)
+ local status, err = ltn12.pump.step(source, sink)
+ if err then
+ log:warn(err)
+ self:close()
+ end
end,
0) -- no timeout
+
+ return true
+end
+
+
+function close(self)
+ -- cancel queued requests
+ for i, task in ipairs(self.responseQueue) do
+ task:addTask(nil, "closed")
+ end
+ self.responseQueue = {}
+
+ Socket.close(self)
end
@@ -563,11 +603,34 @@
assert(task, "Wireless:request must be called in a Task")
log:info("REQUEST: ", ...)
- self.t_sock:request(...)
+
+ -- open the socket if it is closed
+ if not self.t_sock and not self:open() then
+ -- XXXX callers expect a string
+ return "", "closed"
+ end
+
+ local status, err = self.t_sock:request(...)
+
+ if err then
+ log:warn(err)
+ self:close()
+
+ -- XXXX callers expect a string
+ return "", err
+ end
-- yield task
table.insert(self.responseQueue, task)
- local _, reply = Task:yield(false)
+ local _, reply, err = Task:yield(false)
+
+ if err then
+ log:warn(err)
+ self:close()
+
+ -- XXXX callers expect a string
+ return "", err
+ end
log:info("REPLY:", reply)
return reply
Modified: trunk/jive/src/pkg/jive_squeezeboxjive/src/jive_wireless.c
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive_squeezeboxjive/src/jive_wireless.c?rev=1848&root=Jive&r1=1847&r2=1848&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive_squeezeboxjive/src/jive_wireless.c (original)
+++ trunk/jive/src/pkg/jive_squeezeboxjive/src/jive_wireless.c Thu Feb 7
07:19:18 2008
@@ -10,33 +10,52 @@
#include "wpa_ctrl.h"
-static struct wpa_ctrl *open_wpa_ctrl(lua_State *L) {
+static int jive_net_wpa_ctrl_open(lua_State *L) {
const char *ctrl_path;
- struct wpa_ctrl *ctrl;
+ struct wpa_ctrl **ctrl;
int err;
+
+ /* stack is:
+ * 1: JiveWPA
+ * 2: ctrl_path
+ */
// FIXME allow variable control path
ctrl_path = "/var/run/wpa_supplicant/eth0";
- ctrl = wpa_ctrl_open(ctrl_path);
- if (ctrl == NULL) {
- luaL_error(L, "cannot open wpa_cli %s", ctrl_path);
+ ctrl = lua_newuserdata(L, sizeof(struct wpa_ctrl **));
+
+ *ctrl = wpa_ctrl_open(ctrl_path);
+ if (*ctrl == NULL) {
+ lua_pushnil(L);
+ lua_pushfstring(L, "cannot open wpa_cli %s", ctrl_path);
+ return 2;
}
- err = wpa_ctrl_attach(ctrl);
+ err = wpa_ctrl_attach(*ctrl);
if (err == -1) {
- wpa_ctrl_close(ctrl);
- luaL_error(L, "wpa_ctrl_attach error");
+ wpa_ctrl_close(*ctrl);
+
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl attach error");
+ return 2;
}
if (err == -2) {
- wpa_ctrl_close(ctrl);
- luaL_error(L, "wpa_ctrl_attach timeout");
+ wpa_ctrl_close(*ctrl);
+
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl attach timeout");
+ return 2;
}
- return ctrl;
+ luaL_getmetatable(L, "jive.wireless");
+ lua_setmetatable(L, -2);
+
+ return 1;
}
-static void close_wpa_ctrl(lua_State *L) {
+
+static int jive_net_wpa_ctrl_close(lua_State *L) {
struct wpa_ctrl **ctrl;
ctrl = (struct wpa_ctrl **)lua_touserdata(L, 1);
@@ -44,29 +63,7 @@
wpa_ctrl_close(*ctrl);
*ctrl = NULL;
}
-}
-
-static int jive_net_wpa_ctrl_open(lua_State *L) {
- //const char *ctrl_path;
- struct wpa_ctrl **ctrl;
-
- /* stack is:
- * 1: JiveWPA
- * 2: ctrl_path
- */
-
- ctrl = lua_newuserdata(L, sizeof(struct wpa_ctrl *));
- *ctrl = open_wpa_ctrl(L);
-
- luaL_getmetatable(L, "jive.wireless");
- lua_setmetatable(L, -2);
-
- return 1;
-}
-
-static int jive_net_wpa_ctrl_gc(lua_State *L) {
- close_wpa_ctrl(L);
return 0;
}
@@ -80,13 +77,23 @@
ctrl = *(struct wpa_ctrl **)lua_touserdata(L, 1);
cmd = lua_tolstring(L, 2, &cmd_len);
+ if (!ctrl) {
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl closed");
+ return 2;
+ }
+
err = wpa_ctrl_request(ctrl, cmd, cmd_len, NULL, NULL, NULL);
if (err == -1) {
- close_wpa_ctrl(L);
- luaL_error(L, "wpa_ctrl_request error");
+ jive_net_wpa_ctrl_close(L);
+
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl request error");
+ return 2;
}
- return 0;
+ lua_pushboolean(L, 1);
+ return 1;
}
@@ -94,6 +101,13 @@
struct wpa_ctrl *ctrl;
ctrl = *(struct wpa_ctrl **)lua_touserdata(L, 1);
+
+ if (!ctrl) {
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl closed");
+ return 2;
+ }
+
lua_pushinteger(L, wpa_ctrl_get_fd(ctrl));
return 1;
@@ -108,19 +122,28 @@
ctrl = *(struct wpa_ctrl **)lua_touserdata(L, 1);
+ if (!ctrl) {
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl closed");
+ return 2;
+ }
+
if (!wpa_ctrl_pending(ctrl)) {
lua_pushnil(L);
- return 1;
+ lua_pushstring(L, "timeout");
+ return 2;
}
err = wpa_ctrl_recv(ctrl, reply, &reply_len);
if (err == -1) {
- close_wpa_ctrl(L);
- luaL_error(L, "wpa_ctrl_request error");
+ jive_net_wpa_ctrl_close(L);
+
+ lua_pushnil(L);
+ lua_pushstring(L, "wpa_ctrl recv error");
+ return 2;
}
lua_pushlstring(L, reply, reply_len);
-
return 1;
}
@@ -134,8 +157,11 @@
int luaopen_jiveWireless(lua_State *L) {
luaL_newmetatable(L, "jive.wireless");
- lua_pushcfunction(L, jive_net_wpa_ctrl_gc);
+ lua_pushcfunction(L, jive_net_wpa_ctrl_close);
lua_setfield(L, -2, "__gc");
+
+ lua_pushcfunction(L, jive_net_wpa_ctrl_close);
+ lua_setfield(L, -2, "close");
lua_pushcfunction(L, jive_net_wpa_ctrl_request);
lua_setfield(L, -2, "request");
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins