aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-10-13 16:45:09 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-10-13 16:45:09 +0000
commite0ec82cf5e4e9ca3070ed5a3ff51b1ff927fe7f4 (patch)
treefd6b972516acea5c0155abaef7282a63bb36708f
parent3fb4233b2db4486b6e593546798604bbdaf45613 (diff)
downloadfetchmail-e0ec82cf5e4e9ca3070ed5a3ff51b1ff927fe7f4.tar.gz
fetchmail-e0ec82cf5e4e9ca3070ed5a3ff51b1ff927fe7f4.tar.bz2
fetchmail-e0ec82cf5e4e9ca3070ed5a3ff51b1ff927fe7f4.zip
Add settable server-nonresponse timeout
svn path=/trunk/; revision=325
-rw-r--r--NEWS2
-rw-r--r--driver.c11
-rw-r--r--fetchmail.c7
-rw-r--r--fetchmail.h1
-rw-r--r--fetchmail.man12
-rw-r--r--options.c28
-rw-r--r--rcfile_l.l1
-rw-r--r--rcfile_y.y5
-rw-r--r--sample.rcfile1
-rw-r--r--socket.c11
10 files changed, 50 insertions, 29 deletions
diff --git a/NEWS b/NEWS
index ea7fb299..e4d2f65b 100644
--- 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 --
diff --git a/driver.c b/driver.c
index 9fb1e69f..45f17344 100644
--- 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);
}
diff --git a/fetchmail.c b/fetchmail.c
index 5299b25a..b21cdaef 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -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",
diff --git a/fetchmail.h b/fetchmail.h
index 24d8d0ab..8120af3d 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -74,6 +74,7 @@ struct hostrec
int protocol;
int port;
int authenticate;
+ int timeout;
/* MDA arguments */
char *mda_argv[32];
diff --git a/fetchmail.man b/fetchmail.man
index 863d242d..f8e3236f 100644
--- a/fetchmail.man
+++ b/fetchmail.man
@@ -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
diff --git a/options.c b/options.c
index f74ff03d..f85ff2d1 100644
--- a/options.c
+++ b/options.c
@@ -30,18 +30,19 @@
#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);
diff --git a/rcfile_l.l b/rcfile_l.l
index ffd4fadd..a6bb0cfb 100644
--- a/rcfile_l.l
+++ b/rcfile_l.l
@@ -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; }
diff --git a/rcfile_y.y b/rcfile_y.y
index 2985fc6c..105570e1 100644
--- a/rcfile_y.y
+++ b/rcfile_y.y
@@ -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
}
diff --git a/sample.rcfile b/sample.rcfile
index 42ad1362..8cb7aa87 100644
--- a/sample.rcfile
+++ b/sample.rcfile
@@ -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
diff --git a/socket.c b/socket.c
index 62ea92b5..24d86ee8 100644
--- 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