From 32577be4b9f9eee455f8ab02828fee69bf033c35 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 29 Jul 2009 03:53:16 +0000 Subject: [PATCH] luci-0.9: merge r5154-r5161 --- libs/core/luasrc/store.lua | 16 +++++++++++++ libs/core/luasrc/util.lua | 27 +++++++++++----------- .../luasrc/lucid/http/LuciWebPublisher.lua | 7 ++++++ libs/lucid-http/luasrc/lucid/http/server.lua | 8 +++++-- libs/lucid/hostfiles/etc/config/lucid | 2 +- libs/lucid/luasrc/lucid.lua | 6 +++++ libs/lucid/root/etc/config/lucid | 1 + libs/nixio/lua/nixio/util.lua | 4 ++-- .../luasrc/model/cbi/freifunk/public_status.lua | 3 ++- 9 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 libs/core/luasrc/store.lua diff --git a/libs/core/luasrc/store.lua b/libs/core/luasrc/store.lua new file mode 100644 index 000000000..c33ef07e1 --- /dev/null +++ b/libs/core/luasrc/store.lua @@ -0,0 +1,16 @@ +--[[ + +LuCI - Lua Development Framework +(c) 2009 Steven Barth +(c) 2009 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +]]-- + +local util = require "luci.util" +module("luci.store", util.threadlocal) \ No newline at end of file diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index a3ba43246..9747a4486 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -114,19 +114,16 @@ end -- Scope manipulation routines -- ---- Create a new or get an already existing thread local store associated with --- the current active coroutine. A thread local store is private a table object --- whose values can't be accessed from outside of the running coroutine. --- @return Table value representing the corresponding thread local store -function threadlocal() - local tbl = {} +local tl_meta = { + __mode = "k", - local function get(self, key) - local t = rawget(self, coxpt[coroutine.running()] or coroutine.running() or 0) + __index = function(self, key) + local t = rawget(self, coxpt[coroutine.running()] + or coroutine.running() or 0) return t and t[key] - end + end, - local function set(self, key, value) + __newindex = function(self, key, value) local c = coxpt[coroutine.running()] or coroutine.running() or 0 if not rawget(self, c) then rawset(self, c, { [key] = value }) @@ -134,10 +131,14 @@ function threadlocal() rawget(self, c)[key] = value end end +} - setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"}) - - return tbl +--- Create a new or get an already existing thread local store associated with +-- the current active coroutine. A thread local store is private a table object +-- whose values can't be accessed from outside of the running coroutine. +-- @return Table value representing the corresponding thread local store +function threadlocal(tbl) + return setmetatable(tbl or {}, tl_meta) end diff --git a/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua index 0d0648967..cd33caff9 100644 --- a/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua +++ b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua @@ -52,11 +52,18 @@ function factory(server, config) end end + local mypath if type(config.virtual) == "table" then for _, v in ipairs(config.virtual) do + mypath = mypath or v vhost:set_handler(v, handler) end else + mypath = config.virtual vhost:set_handler(config.virtual, handler) end + + if config.home then + vhost.default = mypath + end end \ No newline at end of file diff --git a/libs/lucid-http/luasrc/lucid/http/server.lua b/libs/lucid-http/luasrc/lucid/http/server.lua index 24eb042ce..53531a516 100644 --- a/libs/lucid-http/luasrc/lucid/http/server.lua +++ b/libs/lucid-http/luasrc/lucid/http/server.lua @@ -173,6 +173,10 @@ function VHost.process(self, request, ...) -- Call URI part request.env.PATH_INFO = uri + if self.default and uri == "/" then + return 302, {Location = self.default} + end + for k, h in pairs(self.handlers) do if #k > hlen then if uri == k or (uri:sub(1, #k) == k and uri:byte(#k+1) == sc) then @@ -365,8 +369,8 @@ function Server.process(self, client, env) set_memory_limit(env.config.memlimit) end - client:setsockopt("socket", "rcvtimeo", 5) - client:setsockopt("socket", "sndtimeo", 5) + client:setsockopt("socket", "rcvtimeo", 60) + client:setsockopt("socket", "sndtimeo", 60) repeat -- parse headers diff --git a/libs/lucid/hostfiles/etc/config/lucid b/libs/lucid/hostfiles/etc/config/lucid index 934faa10e..22b7efad9 100644 --- a/libs/lucid/hostfiles/etc/config/lucid +++ b/libs/lucid/hostfiles/etc/config/lucid @@ -19,6 +19,7 @@ config LuciWebPublisher luciweb option physical '' list virtual /luci option domain '' + option home 1 list exec ':lo' list exec ':br-lan' list exec 'root' @@ -71,4 +72,3 @@ config 'Redirector' 'splashredir' option 'virtual' '/' option 'physical' ':80/luci/splash' - \ No newline at end of file diff --git a/libs/lucid/luasrc/lucid.lua b/libs/lucid/luasrc/lucid.lua index d743269fe..4feb159a5 100644 --- a/libs/lucid/luasrc/lucid.lua +++ b/libs/lucid/luasrc/lucid.lua @@ -60,6 +60,12 @@ function start() run() end +--- Returns the PID of the currently active LuCId process. +function running() + local pid = tonumber(state:get(UCINAME, "main", "pid")) + return pid and nixio.kill(pid, 0) and pid +end + --- Stops any running LuCId superprocess. function stop() local pid = tonumber(state:get(UCINAME, "main", "pid")) diff --git a/libs/lucid/root/etc/config/lucid b/libs/lucid/root/etc/config/lucid index c5a3f3d8e..07c32c16c 100644 --- a/libs/lucid/root/etc/config/lucid +++ b/libs/lucid/root/etc/config/lucid @@ -15,6 +15,7 @@ config DirectoryPublisher webroot config LuciWebPublisher luciweb option name 'LuCI Webapplication' option physical '' + option home 1 list virtual /luci list virtual /cgi-bin/luci option domain '' diff --git a/libs/nixio/lua/nixio/util.lua b/libs/nixio/lua/nixio/util.lua index 401ec615e..409004882 100644 --- a/libs/nixio/lua/nixio/util.lua +++ b/libs/nixio/lua/nixio/util.lua @@ -14,8 +14,8 @@ $Id$ local table = require "table" local nixio = require "nixio" -local getmetatable, assert, pairs, type, tostring = - getmetatable, assert, pairs, type, tostring +local getmetatable, assert, pairs, type = getmetatable, assert, pairs, type +local tostring = tostring module "nixio.util" diff --git a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua index 2192697fd..2363c8c7f 100644 --- a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua +++ b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua @@ -27,11 +27,12 @@ f:field(DummyValue, "_memtotal", translate("m_i_memory")).value = string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", tonumber(memtotal) / 1024, 100 * memcached / memtotal, - tostring(translate("mem_cached"), "")), + tostring(translate("mem_cached", "")), 100 * membuffers / memtotal, tostring(translate("mem_buffered", "")), 100 * memfree / memtotal, tostring(translate("mem_free", "")) +) f:field(DummyValue, "_systime", translate("m_i_systemtime")).value = os.date("%c") -- 2.11.0