Commit e0ec82cf authored by Eric S. Raymond's avatar Eric S. Raymond

Add settable server-nonresponse timeout

svn path=/trunk/; revision=325
parent 3fb4233b
......@@ -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 --
......
......@@ -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);
}
......@@ -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",
......
......@@ -74,6 +74,7 @@ struct hostrec
int protocol;
int port;
int authenticate;
int timeout;
/* MDA arguments */
char *mda_argv[32];
......
......@@ -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
......
......@@ -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);
......
......@@ -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; }
......
......@@ -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
}
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment