Software /
code /
prosody
Comparison
plugins/mod_posix.lua @ 8663:a7a9d9511dc1
mod_posix: Delay setting signal handlers until in the main thread
Signal handlers work by setting a debug hook. Hooks are per-thread, so we need this to be called in the main thread. However module loading is not in the main thread anymore.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Mar 2018 21:18:58 +0000 |
parent | 8235:7d9a2c200736 |
child | 9763:982529dd0bed |
comparison
equal
deleted
inserted
replaced
8662:a4e63b037a2a | 8663:a7a9d9511dc1 |
---|---|
159 | 159 |
160 module:hook("server-stopped", remove_pidfile); | 160 module:hook("server-stopped", remove_pidfile); |
161 | 161 |
162 -- Set signal handlers | 162 -- Set signal handlers |
163 if have_signal then | 163 if have_signal then |
164 signal.signal("SIGTERM", function () | 164 module:add_timer(0, function () |
165 module:log("warn", "Received SIGTERM"); | 165 signal.signal("SIGTERM", function () |
166 prosody.unlock_globals(); | 166 module:log("warn", "Received SIGTERM"); |
167 prosody.shutdown("Received SIGTERM"); | 167 prosody.unlock_globals(); |
168 prosody.lock_globals(); | 168 prosody.shutdown("Received SIGTERM"); |
169 end); | 169 prosody.lock_globals(); |
170 end); | |
170 | 171 |
171 signal.signal("SIGHUP", function () | 172 signal.signal("SIGHUP", function () |
172 module:log("info", "Received SIGHUP"); | 173 module:log("info", "Received SIGHUP"); |
173 prosody.reload_config(); | 174 prosody.reload_config(); |
174 prosody.reopen_logfiles(); | 175 prosody.reopen_logfiles(); |
175 end); | 176 end); |
176 | 177 |
177 signal.signal("SIGINT", function () | 178 signal.signal("SIGINT", function () |
178 module:log("info", "Received SIGINT"); | 179 module:log("info", "Received SIGINT"); |
179 prosody.unlock_globals(); | 180 prosody.unlock_globals(); |
180 prosody.shutdown("Received SIGINT"); | 181 prosody.shutdown("Received SIGINT"); |
181 prosody.lock_globals(); | 182 prosody.lock_globals(); |
183 end); | |
182 end); | 184 end); |
183 end | 185 end |