Software /
code /
prosody
Annotate
plugins/mod_scansion_record.lua @ 13652:a08065207ef0
net.server_epoll: Call :shutdown() on TLS sockets when supported
Comment from Matthew:
This fixes a potential issue where the Prosody process gets blocked on sockets
waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends
layer 7 data, and this can cause problems for sockets which are in the process
of being cleaned up.
This depends on LuaSec changes which are not yet upstream.
From Martijn's original email:
So first my analysis of luasec. in ssl.c the socket is put into blocking
mode right before calling SSL_shutdown() inside meth_destroy(). My best
guess to why this is is because meth_destroy is linked to the __close
and __gc methods, which can't exactly be called multiple times and
luasec does want to make sure that a tls session is shutdown as clean
as possible.
I can't say I disagree with this reasoning and don't want to change this
behaviour. My solution to this without changing the current behaviour is
to introduce a shutdown() method. I am aware that this overlaps in a
conflicting way with tcp's shutdown method, but it stays close to the
OpenSSL name. This method calls SSL_shutdown() in the current
(non)blocking mode of the underlying socket and returns a boolean
whether or not the shutdown is completed (matching SSL_shutdown()'s 0
or 1 return values), and returns the familiar ssl_ioerror() strings on
error with a false for completion. This error can then be used to
determine if we have wantread/wantwrite to finalize things. Once
meth_shutdown() has been called once a shutdown flag will be set, which
indicates to meth_destroy() that the SSL_shutdown() has been handled
by the application and it shouldn't be needed to set the socket to
blocking mode. I've left the SSL_shutdown() call in the
LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a
timeout for the shutdown code, which might allow SSL_shutdown() to
clean up anyway at the last possible moment.
Another thing I've changed to luasec is the call to socket_setblocking()
right before calling close(2) in socket_destroy() in usocket.c.
According to the latest POSIX[0]:
Note that the requirement for close() on a socket to block for up to
the current linger interval is not conditional on the O_NONBLOCK
setting.
Which I read to mean that removing O_NONBLOCK on the socket before close
doesn't impact the behaviour and only causes noise in system call
tracers. I didn't touch the windows bits of this, since I don't do
windows.
For the prosody side of things I've made the TLS shutdown bits resemble
interface:onwritable(), and put it under a combined guard of self._tls
and self.conn.shutdown. The self._tls bit is there to prevent getting
stuck on this condition, and self.conn.shutdown is there to prevent the
code being called by instances where the patched luasec isn't deployed.
The destroy() method can be called from various places and is read by
me as the "we give up" error path. To accommodate for these unexpected
entrypoints I've added a single call to self.conn:shutdown() to prevent
the socket being put into blocking mode. I have no expectations that
there is any other use here. Same as previous, the self.conn.shutdown
check is there to make sure it's not called on unpatched luasec
deployments and self._tls is there to make sure we don't call shutdown()
on tcp sockets.
I wouldn't recommend logging of the conn:shutdown() error inside
close(), since a lot of clients simply close the connection before
SSL_shutdown() is done.
author | Martijn van Duren <martijn@openbsd.org> |
---|---|
date | Thu, 06 Feb 2025 15:04:38 +0000 |
parent | 12977:74b9e05af71e |
rev | line source |
---|---|
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local names = { "Romeo", "Juliet", "Mercutio", "Tybalt", "Benvolio" }; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local devices = { "", "phone", "laptop", "tablet", "toaster", "fridge", "shoe" }; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local users = {}; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12110
diff
changeset
|
5 local filters = require "prosody.util.filters"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12110
diff
changeset
|
6 local id = require "prosody.util.id"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12110
diff
changeset
|
7 local dt = require "prosody.util.datetime"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12110
diff
changeset
|
8 local dm = require "prosody.util.datamanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12110
diff
changeset
|
9 local st = require "prosody.util.stanza"; |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
12110
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
11254
diff
changeset
|
11 local record_id = id.short():lower(); |
9361
3620f7b3517b
mod_scansion_record: Split up construction of filename for reuse of parts later
Kim Alvefur <zash@zash.se>
parents:
9360
diff
changeset
|
12 local record_date = os.date("%Y%b%d"):lower(); |
9369
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
13 local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true); |
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
14 local record_file = dm.getpath(record_id, "scansion", record_date, "log", true); |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
9364
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
16 local head = io.open(header_file, "w"); |
9369
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
17 local scan = io.open(record_file, "w+"); |
9346
2946f2bd2bb5
mod_scansion_record: Open log file
Kim Alvefur <zash@zash.se>
parents:
9345
diff
changeset
|
18 |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local function record(string) |
9357
0ae20fb3d4c6
mod_scansion_record: Rename main file handle
Kim Alvefur <zash@zash.se>
parents:
9356
diff
changeset
|
20 scan:write(string); |
11254
613035d6e5a0
mod_scansion_record: Flush after writes
Matthew Wild <mwild1@gmail.com>
parents:
10718
diff
changeset
|
21 scan:flush(); |
9348
e1de3245c696
mod_scansion_record: Finish function for writing data
Kim Alvefur <zash@zash.se>
parents:
9347
diff
changeset
|
22 end |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
9364
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
24 local function record_header(string) |
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
25 head:write(string); |
11254
613035d6e5a0
mod_scansion_record: Flush after writes
Matthew Wild <mwild1@gmail.com>
parents:
10718
diff
changeset
|
26 head:flush(); |
9364
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
27 end |
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
28 |
9368
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
29 local function record_object(class, name, props) |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
30 head:write(("[%s] %s\n"):format(class, name)); |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
31 for k,v in pairs(props) do |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
32 head:write(("\t%s: %s\n"):format(k, v)); |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
33 end |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
34 head:write("\n"); |
11254
613035d6e5a0
mod_scansion_record: Flush after writes
Matthew Wild <mwild1@gmail.com>
parents:
10718
diff
changeset
|
35 head:flush(); |
9368
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
36 end |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
37 |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 local function record_event(session, event) |
9351
b37f131d68c2
mod_scansion_record: Complete stanza recording functions
Kim Alvefur <zash@zash.se>
parents:
9350
diff
changeset
|
39 record(session.scansion_id.." "..event.."\n\n"); |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 local function record_stanza(stanza, session, verb) |
10718
d229e4d31598
mod_scansion_record: Indent stanzas in recordings
Kim Alvefur <zash@zash.se>
parents:
9619
diff
changeset
|
43 local flattened = tostring(stanza:indent(2, "\t")); |
9619
7172077c0a53
mod_scansion_record: Split stanzas into multiple lines
Kim Alvefur <zash@zash.se>
parents:
9618
diff
changeset
|
44 record(session.scansion_id.." "..verb..":\n\t"..flattened.."\n\n"); |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 local function record_stanza_in(stanza, session) |
9358
bbc24fc734da
mod_scansion_record: Only record stanzas in the default namespace
Kim Alvefur <zash@zash.se>
parents:
9357
diff
changeset
|
48 if stanza.attr.xmlns == nil then |
9618
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
49 local copy = st.clone(stanza); |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
50 copy.attr.from = nil; |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
51 record_stanza(copy, session, "sends") |
9358
bbc24fc734da
mod_scansion_record: Only record stanzas in the default namespace
Kim Alvefur <zash@zash.se>
parents:
9357
diff
changeset
|
52 end |
9351
b37f131d68c2
mod_scansion_record: Complete stanza recording functions
Kim Alvefur <zash@zash.se>
parents:
9350
diff
changeset
|
53 return stanza; |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 local function record_stanza_out(stanza, session) |
9358
bbc24fc734da
mod_scansion_record: Only record stanzas in the default namespace
Kim Alvefur <zash@zash.se>
parents:
9357
diff
changeset
|
57 if stanza.attr.xmlns == nil then |
9359
dc55d7d2798b
mod_scansion_record: Avoid recording the resource binding stanza
Kim Alvefur <zash@zash.se>
parents:
9358
diff
changeset
|
58 if not (stanza.name == "iq" and stanza:get_child("bind", "urn:ietf:params:xml:ns:xmpp-bind")) then |
9618
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
59 local copy = st.clone(stanza); |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
60 if copy.attr.to == session.full_jid then |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
61 copy.attr.to = nil; |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
62 end |
d6e6e1fb7ef0
mod_scansion_record: Discard from/to where these are implicitly the sessions full JID
Kim Alvefur <zash@zash.se>
parents:
9373
diff
changeset
|
63 record_stanza(copy, session, "receives"); |
9359
dc55d7d2798b
mod_scansion_record: Avoid recording the resource binding stanza
Kim Alvefur <zash@zash.se>
parents:
9358
diff
changeset
|
64 end |
9358
bbc24fc734da
mod_scansion_record: Only record stanzas in the default namespace
Kim Alvefur <zash@zash.se>
parents:
9357
diff
changeset
|
65 end |
9351
b37f131d68c2
mod_scansion_record: Complete stanza recording functions
Kim Alvefur <zash@zash.se>
parents:
9350
diff
changeset
|
66 return stanza; |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 module:hook("resource-bind", function (event) |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 local session = event.session; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 if not users[session.username] then |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 users[session.username] = { |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 character = table.remove(names, 1) or id.short(); |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 devices = {}; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 n_devices = 0; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 }; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 local user = users[session.username]; |
9354
b042aa047d80
mod_scansion_record: Correctly retrieve resource
Kim Alvefur <zash@zash.se>
parents:
9353
diff
changeset
|
79 local device = user.devices[session.resource]; |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 if not device then |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 user.n_devices = user.n_devices + 1; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 device = devices[user.n_devices] or ("device"..id.short()); |
9354
b042aa047d80
mod_scansion_record: Correctly retrieve resource
Kim Alvefur <zash@zash.se>
parents:
9353
diff
changeset
|
83 user.devices[session.resource] = device; |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 end |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 session.scansion_character = user.character; |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 session.scansion_device = device; |
9350
07fd880905a3
mod_scansion_record: Remove extra "
Kim Alvefur <zash@zash.se>
parents:
9349
diff
changeset
|
87 session.scansion_id = user.character..(device ~= "" and "'s "..device or device); |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 |
9370
7872abb9fc1f
mod_scansion_record: Record the full identity including device name
Kim Alvefur <zash@zash.se>
parents:
9369
diff
changeset
|
89 record_object("Client", session.scansion_id, { |
9368
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
90 jid = session.full_jid, |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
91 password = "password", |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
92 }); |
0c5177738ffd
mod_scansion_record: Record connected clients as scansion Objects declarations
Kim Alvefur <zash@zash.se>
parents:
9367
diff
changeset
|
93 |
9372
0e685b7ec039
mod_scansion_record: Lower log message to 'info' level
Kim Alvefur <zash@zash.se>
parents:
9371
diff
changeset
|
94 module:log("info", "Connected: %s", session.scansion_id); |
9352
0fdb70ad9fcc
mod_scansion_record: Record session connecting
Kim Alvefur <zash@zash.se>
parents:
9351
diff
changeset
|
95 record_event(session, "connects"); |
9344
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 filters.add_filter(session, "stanzas/in", record_stanza_in); |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 filters.add_filter(session, "stanzas/out", record_stanza_out); |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 end); |
d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 |
9373
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
101 module:hook("resource-unbind", function (event) |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
102 local session = event.session; |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
103 if session.scansion_id then |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
104 record_event(session, "disconnects"); |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
105 end |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
106 end) |
1a69803d5d5d
mod_scansion_record: Record disconnection
Kim Alvefur <zash@zash.se>
parents:
9372
diff
changeset
|
107 |
9365
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
108 record_header("# mod_scansion_record on host '"..module.host.."' recording started "..dt.datetime().."\n\n"); |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
109 |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
110 record[[ |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
111 ----- |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
112 |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
113 ]] |
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
114 |
9360
0444e321b757
mod_scansion_record: Hook correct shutdown event
Kim Alvefur <zash@zash.se>
parents:
9359
diff
changeset
|
115 module:hook_global("server-stopping", function () |
9365
acb316319dc0
mod_scansion_record: Generate a header with hostname and timestamp
Kim Alvefur <zash@zash.se>
parents:
9364
diff
changeset
|
116 record("# recording ended on "..dt.datetime().."\n"); |
9369
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
117 module:log("info", "Scansion recording available in %s", header_file); |
9366
9472b4044fc6
mod_scansion_record: Close files in the cleanup stage of shutdown (fixes use after close)
Kim Alvefur <zash@zash.se>
parents:
9365
diff
changeset
|
118 end); |
9472b4044fc6
mod_scansion_record: Close files in the cleanup stage of shutdown (fixes use after close)
Kim Alvefur <zash@zash.se>
parents:
9365
diff
changeset
|
119 |
9472b4044fc6
mod_scansion_record: Close files in the cleanup stage of shutdown (fixes use after close)
Kim Alvefur <zash@zash.se>
parents:
9365
diff
changeset
|
120 prosody.events.add_handler("server-cleanup", function () |
9369
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
121 scan:seek("set", 0); |
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
122 for line in scan:lines() do |
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
123 head:write(line, "\n"); |
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
124 end |
9362
31317e8edbbc
mod_scansion_record: Fix missed rename of file handle
Kim Alvefur <zash@zash.se>
parents:
9361
diff
changeset
|
125 scan:close(); |
9369
dd452f932b67
mod_scansion_record: Merge header and log into one file at shutdown
Kim Alvefur <zash@zash.se>
parents:
9368
diff
changeset
|
126 os.remove(record_file); |
9364
62f9127ab493
mod_scansion_record: Open a related file for header entries
Kim Alvefur <zash@zash.se>
parents:
9363
diff
changeset
|
127 head:close() |
9347
9479523e209a
mod_scansion_record: and close it on shutdown
Kim Alvefur <zash@zash.se>
parents:
9346
diff
changeset
|
128 end); |