fetchmail-friends
[Top] [All Lists]

[fetchmail] Extension to "monitor" for polling interface status

2002-09-09 15:22:55
Hi,

The "monitor" function tests a local interface for activity and inhibits the fetchmail server from polling for mail if there is none. The attached patch enhances this function to give the capability to monitor status of anything e.g. an external dial on demand router and inhibit polling as appropriate. It takes advantage of the fact that fetchmail does not verify the argument to the monitor command which normally takes an interface id. With this enhancement if the argument starts with a "/" then it is assumed to be a path to a program. The program is executed at poll time and if it returns status success then polling is
inhibited.  No errors are reported e.g program not found, not executable.

The patch only inserts new code into interfaces.c - it does not change any existing
code lines.  It works for me on 5.9.13.  I've not tried on 5.9.14.

Yours under GPL for what it's worth; enjoy.

Dick









--- interface.c.orig    Tue Jul 30 20:33:15 2002
+++ interface.c Tue Jul 30 21:13:03 2002
@@ -30,6 +30,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
+#include <sys/wait.h>
 #if defined(__FreeBSD__)
 #if defined __FreeBSD_USE_KVM
     #if __FreeBSD_version >= 300001
@@ -655,6 +656,31 @@
 #endif
 }
 
+int check_online(char *filename) {
+  /* execs filename returns status code or <0 if error.  RJM027 */
+  int status = 0;
+  int err = 0;
+  int pid;
+
+  if ( (pid = fork() )  >=  0 ) {
+    if (pid == 0) {                     /* child process */
+
+      char * basename = strrchr(filename, '/') +1;
+      if (!basename) basename = filename;
+      err = execlp( filename, basename, (char *) 0); /* error ignored */
+      exit(err);                        /* thats all for the child */
+    }
+    else                                /* parent waits for child */
+      err = waitpid(pid, &status, 0);   
+
+  }
+  else                                  /* fork failed */
+    err = pid;
+  if (err > 0) err = 0;
+  return  WEXITSTATUS(status) | err;
+}
+
+
 int interface_approve(struct hostdata *hp, flag domonitor)
 /* return TRUE if OK to poll, FALSE otherwise */
 {
@@ -699,6 +725,21 @@
                      GT_("activity on %s checked as %d\n"), 
                      hp->monitor, hp->monitor_io);
 #endif
+
+        /* if interface name begins with / then assume its path of prog
+          to test line status.  Should return success to skip poll.  RJM027*/
+       if (*hp->monitor == '/') {       /* its a filename */
+         if (check_online(hp->monitor))
+           return(TRUE);                /* OK to poll or err */
+         else {                         /* skip poll */
+           (void) report(stdout, 
+                         GT_("skipping poll of %s, %s success\n"),
+                         hp->pollname, hp->monitor);
+           return(FALSE);
+         }
+                                        /* never gets out of here */
+       }
+             
        /* if monitoring, check link for activity if it is up */
        if (get_ifinfo(hp->monitor, &ifinfo))
        {
<Prev in Thread] Current Thread [Next in Thread>
  • [fetchmail] Extension to "monitor" for polling interface status, Dick Middleton <=