Configuration fixes. Repair automatic outbound connects.
[ircu2.10.12-pk.git] / ircd / ircd.c
index 2ed022bcb3cde8cab777c9a53cb2a4b279289235..d43f2b33062d8cb12d845f194705b6d84063fe39 100644 (file)
@@ -248,6 +248,7 @@ static void try_connections(struct Event* ev) {
   time_t            next        = 0;
   struct ConnectionClass* cltmp;
   struct Jupe*      ajupe;
+  int hold;
 
   assert(ET_EXPIRE == ev_type(ev));
   assert(0 != ev_timer(ev));
@@ -259,7 +260,6 @@ static void try_connections(struct Event* ev) {
      */
     if (!(aconf->status & CONF_SERVER)
         || aconf->address.port == 0
-        || aconf->hold == 0
         || ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)))
       continue;
 
@@ -267,20 +267,21 @@ static void try_connections(struct Event* ev) {
     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. */
@@ -461,7 +462,7 @@ static void parse_command_line(int argc, char** argv) {
    */
   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;
@@ -636,6 +637,11 @@ int main(int argc, char **argv) {
 
   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();
@@ -674,7 +680,6 @@ int main(int argc, char **argv) {
   }
 
   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);