]> Pileus Git - ~andy/fetchmail/commitdiff
Add settable server-nonresponse timeout
authorEric S. Raymond <esr@thyrsus.com>
Sun, 13 Oct 1996 16:45:09 +0000 (16:45 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 13 Oct 1996 16:45:09 +0000 (16:45 -0000)
svn path=/trunk/; revision=325

NEWS
driver.c
fetchmail.c
fetchmail.h
fetchmail.man
options.c
rcfile_l.l
rcfile_y.y
sample.rcfile
socket.c

diff --git a/NEWS b/NEWS
index ea7fb299118468e9bbf81e68c710001dcc068e3b..e4d2f65b38a82e86fdb990f55fa4be83dc79f846 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ fetchmail-1.9 ():
   foreground without --quit now tries to wake the daemon and force it
   to poll immediately.
 
+* Add option to set server nonresponse timeout.
+
 fetchmail-1.8 (Fri Oct 11 15:08:10 EDT 1996):
 
 features --
index 9fb1e69f4d988d79a264f104cdccde7db41f99f9..45f173448c0feb1b1654825aa8bca362bf2b9e26 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -32,8 +32,8 @@
 
 static struct method *protocol;
 
-static int alarmed; /* A flag to indicate that SIGALRM happened */
-int timeout = CLIENT_TIMEOUT;
+static int alarmed;    /* a flag to indicate that SIGALRM happened */
+static int mytimeout;  /* server-nonresponse timeout for current query */
 
 char tag[TAGLEN];
 static int tagnum;
@@ -476,7 +476,7 @@ struct hostrec *queryctl;
            sizeticker -= SIZETICKER;
 
            /* reset timeout so we don't choke on very long messages */
-           alarm(timeout);
+           alarm(queryctl->timeout);
        }
        lines++;
     }
@@ -581,7 +581,7 @@ struct method *proto;
 
     alarmed = 0;
     sigsave = signal(SIGALRM, alarm_handler);
-    alarm (timeout);
+    alarm (mytimeout = queryctl->timeout);
 
 #ifndef KERBEROS_V4
     if (queryctl->authenticate == A_KERBEROS)
@@ -924,5 +924,6 @@ void
 alarm_handler (int signal)
 {
     alarmed = 1;
-    fprintf(stderr,"fetchmail: timeout after %d seconds.\n", timeout);
+    fprintf(stderr,
+           "fetchmail: timeout after %d seconds.\n", mytimeout);
 }
index 5299b25a7ac13473b26253d5c95b73dadd2e29a7..b21cdaef41a4a75e2336986b3c4e2f6e9b4bcd2d 100644 (file)
@@ -111,7 +111,7 @@ char **argv;
     }
 
     def_opts.protocol = P_AUTO;
-
+    def_opts.timeout = CLIENT_TIMEOUT;
     strcpy(def_opts.remotename, user);
     strcpy(def_opts.smtphost, "localhost");
 
@@ -544,6 +544,11 @@ struct hostrec *queryctl;
     putchar('\n');
     if (queryctl->authenticate == A_KERBEROS)
            printf("  Kerberos authentication enabled.\n");
+    printf("  Server nonresponse timeout is %d seconds", queryctl->timeout);
+    if (queryctl->timeout ==  CLIENT_TIMEOUT)
+       printf(" (default).\n");
+    else
+       printf("\n.");
 
     printf("  %s messages will be retrieved (--all %s).\n",
           queryctl->fetchall ? "All" : "Only new",
index 24d8d0abcf63797160bd71217d6a47914a8dd383..8120af3dd0a7d3b53b50f044e7a53ad61435cd80 100644 (file)
@@ -74,6 +74,7 @@ struct hostrec
     int protocol;
     int port;
     int authenticate;
+    int timeout;
 
     /* MDA arguments */
     char *mda_argv[32];
index 863d242dcd53729af66f9b578a8f88f7cbba1fa4..f8e3236fc3af251c63608453e451b10ed825823f 100644 (file)
@@ -284,6 +284,17 @@ will kill a running daemon process.  Otherwise, calling fetchmail with
 a daemon in the background sends a wakeup signal to the daemon,
 forcing it to poll mailservers immediately.
 .PP
+The 
+.B -t
+or
+.B --timeout
+option allows you to set a server-nonresponse timeout in seconds.  If
+a mailserver does not send a greeting message or respond to commands for
+the given number of seconds, \fIfetchmail\fR will hang up on it.
+Without such a timeout \fIfetchmail\fR might hang up indefinitely
+trying to fetch mail from a down host.  This would be particularly
+annoying for a server running in background.
+.PP
 The
 .B -L
 or
@@ -368,6 +379,7 @@ Legal server options are:
     skip
     noskip
     authenticate (or auth)
+    timeout
 
 Legal user options are
 
index f74ff03d4d6045c671ed6ae335dcbd28191bb587..f85ff2d1d995ba3a1cee73f1159debc742071fbf 100644 (file)
--- a/options.c
+++ b/options.c
 #define LA_PROTOCOL    11
 #define LA_PORT                12
 #define LA_AUTHENTICATE        13
-#define LA_USERNAME    14
-#define LA_ALL          15
-#define LA_KILL                16
-#define        LA_KEEP         17
-#define LA_FLUSH        18
-#define LA_NOREWRITE   19
-#define LA_REMOTEFILE  20
-#define LA_SMTPHOST    21
-#define LA_MDA         22
-#define LA_YYDEBUG     23
+#define LA_TIMEOUT     14
+#define LA_USERNAME    15
+#define LA_ALL          16
+#define LA_KILL                17
+#define        LA_KEEP         18
+#define LA_FLUSH        19
+#define LA_NOREWRITE   20
+#define LA_REMOTEFILE  21
+#define LA_SMTPHOST    22
+#define LA_MDA         23
+#define LA_YYDEBUG     24
 
-static char *shortoptions = "?Vcsvd:qL:f:i:p:P:A:u:akKFnr:S:m:y";
+static char *shortoptions = "?Vcsvd:qL:f:i:p:P:A:t:u:akKFnr:S:m:y";
 static struct option longoptions[] = {
   {"help",     no_argument,       (int *) 0, LA_HELP        },
   {"version",   no_argument,       (int *) 0, LA_VERSION     },
@@ -58,6 +59,7 @@ static struct option longoptions[] = {
   {"proto",    required_argument, (int *) 0, LA_PROTOCOL    },
   {"port",     required_argument, (int *) 0, LA_PORT        },
   {"auth",     required_argument, (int *) 0, LA_AUTHENTICATE},
+  {"timeout",  required_argument, (int *) 0, LA_TIMEOUT     },
 
   {"user",     required_argument, (int *) 0, LA_USERNAME    },
   {"username",  required_argument, (int *) 0, LA_USERNAME    },
@@ -190,6 +192,9 @@ struct hostrec *queryctl;
                errflag++;
            }
            break;
+       case 't':
+           queryctl->timeout = atoi(optarg);
+           break;
        case 'u':
        case LA_USERNAME:
            strncpy(queryctl->remotename,optarg,sizeof(queryctl->remotename)-1);
@@ -260,6 +265,7 @@ struct hostrec *queryctl;
        fputs("  -p, --protocol    specify pop2, pop3, imap, apop, rpop, kpop\n", stderr);
        fputs("  -P, --port        TCP/IP service port to connect to\n",stderr);
        fputs("  -A, --auth        authentication type (password or kerberos)\n",stderr);
+       fputs("  -t, --timeout     server nonresponse timeout\n",stderr);
 
        fputs("  -u, --username    specify users's login on server\n", stderr);
        fputs("  -a, --all         retrieve old and new messages\n", stderr);
index ffd4fadd3368cb415e79c9109166e99bf554a70c..a6bb0cfbb7358cb9177e4d118907e24668b0997a 100644 (file)
@@ -28,6 +28,7 @@ proto(col)?   { return PROTOCOL; }
 port           { return PORT; }
 auth(enticate)?        { return AUTHENTICATE; }
 kerberos       { return KERBEROS; }
+timeout                { return TIMEOUT;}
 
 user(name)?    { return USERNAME; }
 pass(word)?    { return PASSWORD; }
index 2985fc6c93d417bd09702afc5ab4bbaaf1b3e7e6..105570e1bd477c98a53d1fbc5aae06d54316d2ec 100644 (file)
@@ -35,7 +35,7 @@ static int prc_errflag;
   char *sval;
 }
 
-%token DEFAULTS SERVER PROTOCOL AUTHENTICATE KPOP KERBEROS
+%token DEFAULTS SERVER PROTOCOL AUTHENTICATE TIMEOUT KPOP KERBEROS
 %token USERNAME PASSWORD FOLDER SMTPHOST MDA IS HERE THERE
 %token <proto> PROTO
 %token <sval>  STRING
@@ -78,6 +78,7 @@ serv_option   : PROTOCOL PROTO        {current.protocol = $2;}
                | SKIP                  {current.skip = ($1==FLAG_TRUE);}
                | AUTHENTICATE PASSWORD {current.authenticate = A_PASSWORD;}
                | AUTHENTICATE KERBEROS {current.authenticate = A_KERBEROS;}
+               | TIMEOUT STRING        {current.timeout = atoi($2);}
                ;
 
 /* the first and only the first user spec may omit the USERNAME part */
@@ -330,6 +331,7 @@ int prc_register()
     FLAG_FORCE(skip);
     FLAG_FORCE(port);
     FLAG_FORCE(authenticate);
+    FLAG_FORCE(timeout);
 #undef FLAG_FORCE
 
     (void) hostalloc(&current);
@@ -370,6 +372,7 @@ struct hostrec *h2;
     FLAG_MERGE(skip);
     FLAG_MERGE(port);
     FLAG_MERGE(authenticate);
+    FLAG_MERGE(timeout);
 #undef FLAG_MERGE
 }
 
index 42ad1362b1c570e863912f84d6b27542bf6e2edd..8cb7aa874382c6b723641adbe6a9047e07545bb2 100644 (file)
@@ -23,6 +23,7 @@
 #   protocol (or proto) -- nuat be followed by a protocol ID
 #   port
 #   authenticate (or auth) -- must be followed by an authentication type
+#   timeout
 #
 #   username (or user)
 #   is
index 62ea92b58bcb7c19834880ad3579b2709077e923..24d86ee81300b5d74dc68bb045a386ca9ba6349f 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -12,7 +12,6 @@
 
 #include <config.h>
 
-#include <signal.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -43,9 +42,6 @@
 
 #define  INTERNAL_BUFSIZE      2048
 
-extern int timeout;
-extern void alarm_handler();
-
 int Socket(host, clientPort)
 char *host;
 int clientPort;
@@ -88,13 +84,6 @@ int len;
 
     while (--len)
     {
-        /* we have to push alarm in case we receive a large message */
-       sigsave = signal (SIGALRM, alarm_handler);
-        if (sigsave == alarm_handler)
-              alarm (timeout);
-        else
-              signal (SIGALRM, sigsave);
-
         if (SockInternalRead(socket, buf, 1) != 1)
             return -1;
         else