]> Pileus Git - ~andy/fetchmail/blobdiff - fetchmail.c
Suppress monitor check after signal wakeup.
[~andy/fetchmail] / fetchmail.c
index 95430c08e942c763f2ab8574510a717342b3a4e7..9954774569db5a6c53c4b749a810ef2ba0be2918 100644 (file)
@@ -38,6 +38,7 @@
 #include <hesiod.h>
 #endif
 
+#include "getopt.h"
 #include "fetchmail.h"
 #include "tunable.h"
 #include "smtp.h"
@@ -124,6 +125,7 @@ int main(int argc, char **argv)
     netrc_entry *netrc_list;
     char *netrc_file, *tmpbuf;
     pid_t pid;
+    int lastsig = 0;
 
 #ifdef __FreeBSD__
     dropprivs();
@@ -236,7 +238,12 @@ int main(int argc, char **argv)
     /* logging should be set up early in case we were restarted from exec */
     if (run.use_syslog)
     {
+#if defined(LOG_MAIL)
        openlog(program_name, LOG_PID, LOG_MAIL);
+#else
+       /* Assume BSD4.2 openlog with two arguments */
+       openlog(program_name, LOG_PID);
+#endif
        report_init(-1);
     }
     else
@@ -620,8 +627,11 @@ int main(int argc, char **argv)
                }
 
 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
-               /* interface_approve() does its own error logging */
-               if (!interface_approve(&ctl->server))
+               /*
+                * Don't do monitoring if we were woken by a signal.
+                * Note that interface_approve() does its own error logging.
+                */
+               if (!interface_approve(&ctl->server, !lastsig))
                    continue;
 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
 
@@ -697,8 +707,6 @@ int main(int argc, char **argv)
         */
        if (run.poll_interval)
        {
-           int lastsig;
-
            /* 
             * Because passwords can expire, it may happen that *all*
             * hosts are now out of the loop due to authfail
@@ -725,11 +733,11 @@ int main(int argc, char **argv)
 
            /*
             * OK, now pause util it's time for the next poll cycle.
-            * A TRUE return indicates we received a wakeup signal;
+            * A nonzero return indicates we received a wakeup signal;
             * unwedge all servers in case the problem has been
             * manually repaired.
             */
-           if ((lastsig = idle(run.poll_interval)))
+           if ((lastsig = interruptible_idle(run.poll_interval)))
            {
 #ifdef SYS_SIGLIST_DECLARED
                report(stdout, 
@@ -756,23 +764,29 @@ int main(int argc, char **argv)
     exit(successes ? PS_SUCCESS : querystatus);
 }
 
-static void optmerge(struct query *h2, struct query *h1, int force)
-/* merge two options records */
+static void list_merge(struct idlist **dstl, struct idlist **srcl, int force)
 {
     /*
-     * If force is off, modify h2 fields only when they're empty (treat h1
-     * as defaults).  If force is on, modify each h2 field whenever h1
-     * is nonempty (treat h1 as an override).  
+     * If force is off, modify dstl fields only when they're empty (treat srcl
+     * as defaults).  If force is on, modify each dstl field whenever scrcl
+     * is nonempty (treat srcl as an override).  
      */
-#define LIST_MERGE(dstl, srcl) if (force ? !!srcl : !dstl) \
-                                               free_str_list(&dstl), \
-                                               append_str_list(&dstl, &srcl)
-    LIST_MERGE(h2->server.localdomains, h1->server.localdomains);
-    LIST_MERGE(h2->localnames, h1->localnames);
-    LIST_MERGE(h2->mailboxes, h1->mailboxes);
-    LIST_MERGE(h2->smtphunt, h1->smtphunt);
-    LIST_MERGE(h2->antispam, h1->antispam);
-#undef LIST_MERGE
+    if (force ? !!*srcl : !*dstl)
+    {
+       struct idlist *cpl = copy_str_list(*srcl);
+
+       append_str_list(dstl, &cpl);
+    }
+}
+
+static void optmerge(struct query *h2, struct query *h1, int force)
+/* merge two options records */
+{
+    list_merge(&h2->server.localdomains, &h1->server.localdomains, force);
+    list_merge(&h2->localnames, &h1->localnames, force);
+    list_merge(&h2->mailboxes, &h1->mailboxes, force);
+    list_merge(&h2->smtphunt, &h1->smtphunt, force);
+    list_merge(&h2->antispam, &h1->antispam, force);
 
 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
     FLAG_MERGE(server.via);