1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-25 19:38:07 +11:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Izaya
f8903ad587
Merge pull request #36 from Hawk777/fix-listeners-deregistering
Do not unregister listeners on unexpected data
2023-07-27 10:08:33 +10:00
Izaya
98fbf0e7d5
Merge pull request #35 from Hawk777/fix-syslog-without-hostname
Fix syslog running with HOSTNAME unset
2023-07-27 10:07:04 +10:00
Izaya
23915e4737
Merge pull request #37 from Hawk777/fix-wrong-listener
Fix registering the wrong listener
2023-07-27 10:06:36 +10:00
Christopher Head
a78a3758f8
Fix registering the wrong listener
The `local_listener` function is obviously intended to be used as the
event listener for locally pushed `syslog` events, to do preliminary
sanity checks and type conversions before calling `wentry`. However, it
was not actually registered as such. Not only does this mean the sanity
checks and type conversions could be skipped, it also means that `rc
syslogd stop` would not work because `wentry` was actually registered as
a listener while `local_listener` was pushed in the `listeners` table,
so `event.ignore` would be passed the wrong value and would not
unregister `wentry`.
2021-01-22 19:26:04 -08:00
Christopher Head
074a980d81
Do not unregister listeners on unexpected data
If a registered event listener callback returns `false`, the listener is
unregistered. A network packet arriving on a different port, or a
message with a missing part, should not cause the syslog system to shut
down. Return `nil` instead of `false` if those sanity checks fail, to
keep the listener registered.
2021-01-22 19:21:23 -08:00
Christopher Head
4f0efd256c
Fix syslog running with HOSTNAME unset
`computer.address` is a function and therefore must be called, not
method-called on directly.
2021-01-22 19:11:26 -08:00

View File

@ -3,7 +3,7 @@ local serial = require "serialization"
local computer = require "computer"
local havenet, net = pcall(require,"minitel")
local hostname = os.getenv("HOSTNAME") or computer.address:sub(1,8)
local hostname = os.getenv("HOSTNAME") or computer.address():sub(1,8)
local cfg = {}
cfg.port = 514
cfg.relay = false
@ -41,7 +41,7 @@ function reload()
f:close()
end
end
hostname = os.getenv("HOSTNAME") or computer.address:sub(1,8)
hostname = os.getenv("HOSTNAME") or computer.address():sub(1,8)
end
local function wentry(_,msg,level,service,host)
@ -69,15 +69,15 @@ local function wentry(_,msg,level,service,host)
end
local function remote_listener(_,from,port,data)
if port ~= cfg.port then return false end
if port ~= cfg.port then return end
local service, level, msg = data:match("(.-)\t(%d)\t(.+)")
if not service or not level or not msg then return false end
if not service or not level or not msg then return end
msg, level, service = tostring(msg),tonumber(level),tostring(service)
wentry(nil,msg,level,service,from)
end
local function local_listener(_,msg,level,service)
if not service or not level or not msg then return false end
if not service or not level or not msg then return end
msg, level, service = tostring(msg),tonumber(level),tostring(service)
wentry(nil,msg,level,service,hostname)
end
@ -85,7 +85,7 @@ end
function start()
reload()
if #listeners > 0 then return end
event.listen("syslog",wentry)
event.listen("syslog",local_listener)
listeners[#listeners+1] = {"syslog",local_listener}
if havenet and cfg.receive then
event.listen("net_msg",remote_listener)