time_t next = 0;
struct ConnectionClass* cltmp;
struct Jupe* ajupe;
+ int hold;
assert(ET_EXPIRE == ev_type(ev));
assert(0 != ev_timer(ev));
*/
if (!(aconf->status & CONF_SERVER)
|| aconf->address.port == 0
- || aconf->hold == 0
|| ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)))
continue;
if (next > aconf->hold || next == 0)
next = aconf->hold;
- /* Skip this entry if its use is still on hold until future, too
- * many links in its connection class, it is already linked, or if
- * connect rules forbid a link now.
- */
+ /* Update the next time we can consider this entry. */
cltmp = aconf->conn_class;
- if ((aconf->hold > CurrentTime)
- || (Links(cltmp) >= MaxLinks(cltmp))
+ hold = aconf->hold > CurrentTime; /* before we update aconf->hold */
+ aconf->hold = ConFreq(cltmp) ? CurrentTime + ConFreq(cltmp) : 0;
+
+ /* Do not try to connect if its use is still on hold until future,
+ * too many links in its connection class, it is already linked,
+ * or if connect rules forbid a link now.
+ */
+ if (hold
+ || (Links(cltmp) > MaxLinks(cltmp))
|| FindServer(aconf->name)
|| conf_eval_crule(aconf->name, CRULE_MASK))
continue;
- /* We want to connect; update entry's hold time. */
- aconf->hold = ConFreq(cltmp) ? CurrentTime + ConFreq(cltmp) : 0;
-
/* Ensure it is at the end of the list for future checks. */
if (aconf->next) {
/* Find aconf's location in the list and splice it out. */
*/
while ((opt = getopt(argc, argv, options)) != EOF)
switch (opt) {
- case 'k': thisServer.bootopt |= BOOT_CHKCONF; break;
+ case 'k': thisServer.bootopt |= BOOT_CHKCONF | BOOT_TTY; break;
case 'n':
case 't': thisServer.bootopt |= BOOT_TTY; break;
case 'd': dpath = optarg; break;
close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF)));
+ /* daemon_init() must be before event_init() because kqueue() FDs
+ * are, perversely, not inherited across fork().
+ */
+ daemon_init(thisServer.bootopt & BOOT_TTY);
+
event_init(MAXCONNECTIONS);
setup_signals();
}
debug_init(thisServer.bootopt & BOOT_TTY);
- daemon_init(thisServer.bootopt & BOOT_TTY);
if (check_pid()) {
Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
exit(2);