| @@ -203,53 +203,72 @@ mDNSlocal void DumpStateLog(mDNS *const | | | @@ -203,53 +203,72 @@ mDNSlocal void DumpStateLog(mDNS *const |
203 | } | | 203 | } |
204 | | | 204 | |
205 | LogMsg("---- END STATE LOG ----"); | | 205 | LogMsg("---- END STATE LOG ----"); |
206 | } | | 206 | } |
207 | | | 207 | |
208 | mDNSlocal mStatus MainLoop(mDNS *m) // Loop until we quit. | | 208 | mDNSlocal mStatus MainLoop(mDNS *m) // Loop until we quit. |
209 | { | | 209 | { |
210 | sigset_t signals; | | 210 | sigset_t signals; |
211 | mDNSBool gotData = mDNSfalse; | | 211 | mDNSBool gotData = mDNSfalse; |
212 | | | 212 | |
213 | mDNSPosixListenForSignalInEventLoop(SIGINT); | | 213 | mDNSPosixListenForSignalInEventLoop(SIGINT); |
214 | mDNSPosixListenForSignalInEventLoop(SIGTERM); | | 214 | mDNSPosixListenForSignalInEventLoop(SIGTERM); |
215 | mDNSPosixListenForSignalInEventLoop(SIGUSR1); | | 215 | mDNSPosixListenForSignalInEventLoop(SIGUSR1); |
| | | 216 | #ifdef HAVE_SIGINFO |
| | | 217 | mDNSPosixListenForSignalInEventLoop(SIGUSR2); |
| | | 218 | mDNSPosixListenForSignalInEventLoop(SIGINFO); |
| | | 219 | #endif |
216 | mDNSPosixListenForSignalInEventLoop(SIGPIPE); | | 220 | mDNSPosixListenForSignalInEventLoop(SIGPIPE); |
217 | mDNSPosixListenForSignalInEventLoop(SIGHUP) ; | | 221 | mDNSPosixListenForSignalInEventLoop(SIGHUP) ; |
218 | | | 222 | |
219 | for (; ;) | | 223 | for (; ;) |
220 | { | | 224 | { |
221 | // Work out how long we expect to sleep before the next scheduled task | | 225 | // Work out how long we expect to sleep before the next scheduled task |
222 | struct timeval timeout; | | 226 | struct timeval timeout; |
223 | mDNSs32 ticks; | | 227 | mDNSs32 ticks; |
224 | | | 228 | |
225 | // Only idle if we didn't find any data the last time around | | 229 | // Only idle if we didn't find any data the last time around |
226 | if (!gotData) | | 230 | if (!gotData) |
227 | { | | 231 | { |
228 | mDNSs32 nextTimerEvent = mDNS_Execute(m); | | 232 | mDNSs32 nextTimerEvent = mDNS_Execute(m); |
229 | nextTimerEvent = udsserver_idle(nextTimerEvent); | | 233 | nextTimerEvent = udsserver_idle(nextTimerEvent); |
230 | ticks = nextTimerEvent - mDNS_TimeNow(m); | | 234 | ticks = nextTimerEvent - mDNS_TimeNow(m); |
231 | if (ticks < 1) ticks = 1; | | 235 | if (ticks < 1) ticks = 1; |
232 | } | | 236 | } |
233 | else // otherwise call EventLoop again with 0 timemout | | 237 | else // otherwise call EventLoop again with 0 timemout |
234 | ticks = 0; | | 238 | ticks = 0; |
235 | | | 239 | |
236 | timeout.tv_sec = ticks / mDNSPlatformOneSecond; | | 240 | timeout.tv_sec = ticks / mDNSPlatformOneSecond; |
237 | timeout.tv_usec = (ticks % mDNSPlatformOneSecond) * 1000000 / mDNSPlatformOneSecond; | | 241 | timeout.tv_usec = (ticks % mDNSPlatformOneSecond) * 1000000 / mDNSPlatformOneSecond; |
238 | | | 242 | |
239 | (void) mDNSPosixRunEventLoopOnce(m, &timeout, &signals, &gotData); | | 243 | (void) mDNSPosixRunEventLoopOnce(m, &timeout, &signals, &gotData); |
240 | | | 244 | |
241 | if (sigismember(&signals, SIGHUP )) Reconfigure(m); | | 245 | if (sigismember(&signals, SIGHUP )) Reconfigure(m); |
| | | 246 | #ifdef HAVE_SIGINFO |
| | | 247 | /* use OSX-compatible signals since we can, and gain enhanced debugging */ |
| | | 248 | if (sigismember(&signals, SIGINFO)) DumpStateLog(m); |
| | | 249 | if (sigismember(&signals, SIGUSR1)) |
| | | 250 | { |
| | | 251 | mDNS_LoggingEnabled = mDNS_LoggingEnabled ? 0 : 1; |
| | | 252 | LogMsg("SIGUSR1: Logging %s", mDNS_LoggingEnabled ? "Enabled" : "Disabled"); |
| | | 253 | } |
| | | 254 | if (sigismember(&signals, SIGUSR2)) |
| | | 255 | { |
| | | 256 | mDNS_PacketLoggingEnabled = mDNS_PacketLoggingEnabled ? 0 : 1; |
| | | 257 | LogMsg("SIGUSR2: Packet Logging %s", mDNS_PacketLoggingEnabled ? "Enabled" : "Disabled"); |
| | | 258 | } |
| | | 259 | #else |
242 | if (sigismember(&signals, SIGUSR1)) DumpStateLog(m); | | 260 | if (sigismember(&signals, SIGUSR1)) DumpStateLog(m); |
| | | 261 | #endif |
243 | // SIGPIPE happens when we try to write to a dead client; death should be detected soon in request_callback() and cleaned up. | | 262 | // SIGPIPE happens when we try to write to a dead client; death should be detected soon in request_callback() and cleaned up. |
244 | if (sigismember(&signals, SIGPIPE)) LogMsg("Received SIGPIPE - ignoring"); | | 263 | if (sigismember(&signals, SIGPIPE)) LogMsg("Received SIGPIPE - ignoring"); |
245 | if (sigismember(&signals, SIGINT) || sigismember(&signals, SIGTERM)) break; | | 264 | if (sigismember(&signals, SIGINT) || sigismember(&signals, SIGTERM)) break; |
246 | } | | 265 | } |
247 | return EINTR; | | 266 | return EINTR; |
248 | } | | 267 | } |
249 | | | 268 | |
250 | int main(int argc, char **argv) | | 269 | int main(int argc, char **argv) |
251 | { | | 270 | { |
252 | mStatus err; | | 271 | mStatus err; |
253 | | | 272 | |
254 | ParseCmdLinArgs(argc, argv); | | 273 | ParseCmdLinArgs(argc, argv); |
255 | | | 274 | |