aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-10-29 18:43:02 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-10-29 18:43:02 +0000
commitd876ad63e12c57aebc5e6d979db9fe57fe951c8a (patch)
tree87a3ee87ecfa9dd3063dc1513b321ea88897f7d0
parent45fa6631f675abd76759238ce665ce960fdcbf5f (diff)
downloadfetchmail-d876ad63e12c57aebc5e6d979db9fe57fe951c8a.tar.gz
fetchmail-d876ad63e12c57aebc5e6d979db9fe57fe951c8a.tar.bz2
fetchmail-d876ad63e12c57aebc5e6d979db9fe57fe951c8a.zip
Fix the damn single-poll-loop bug.
svn path=/trunk/; revision=420
-rw-r--r--NEWS1
-rw-r--r--driver.c19
-rw-r--r--fetchmail.c24
3 files changed, 34 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index c17eb246..12bfed17 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
pl 1.9.5 ():
* Added -N, --nodetach option for debugging purposes.
+* Use interval timers for poll-interval sleep and nonresponse timeout.
pl 1.9.4 (Mon Oct 28 20:58:48 EST 1994):
* Correct status interpretation in closemailpipe() (thanks to Neil Harkins).
diff --git a/driver.c b/driver.c
index 7e72347d..eef6a72c 100644
--- a/driver.c
+++ b/driver.c
@@ -72,8 +72,8 @@ int count; /* length of src */
return len;
}
-static void alarm_handler (int signal)
-/* handle server-timeout signal */
+static void vtalarm_handler (int signal)
+/* handle server-timeout SIGVTALARM signal */
{
longjmp(restart, 1);
}
@@ -784,6 +784,7 @@ const struct method *proto; /* protocol method table */
{
int ok;
void (*sigsave)();
+ struct itimerval ntimeout;
#ifndef KERBEROS_V4
if (ctl->authenticate == A_KERBEROS)
@@ -823,6 +824,13 @@ const struct method *proto; /* protocol method table */
tag[0] = '\0'; /* nuke any tag hanging out from previous query */
ok = 0;
+ /* set up the server-nonresponse timeout */
+ sigsave = signal(SIGVTALRM, vtalarm_handler);
+ ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_sec = 0;
+ ntimeout.it_value.tv_sec = ctl->timeout;
+ ntimeout.it_value.tv_usec = 0;
+ setitimer(ITIMER_VIRTUAL, &ntimeout, (struct itimerval *)NULL);
+
if (setjmp(restart) == 1)
fprintf(stderr,
"fetchmail: timeout after %d seconds waiting for %s.\n",
@@ -832,10 +840,6 @@ const struct method *proto; /* protocol method table */
char buf [POPBUFSIZE+1];
int *msgsizes, socket, len, num, count, new, deletions = 0;
- /* set up the server-nonresponse timeout */
- sigsave = signal(SIGALRM, alarm_handler);
- alarm(ctl->timeout);
-
/* open a socket to the mail server */
if ((socket = Socket(ctl->servername,
ctl->port ? ctl->port : protocol->port))<0)
@@ -1012,8 +1016,7 @@ const struct method *proto; /* protocol method table */
}
}
- alarm(0);
- signal(SIGALRM, sigsave);
+ signal(SIGVTALRM, sigsave);
closeUp:
return(ok);
diff --git a/fetchmail.c b/fetchmail.c
index 7d9a71ca..c834db6a 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -26,6 +26,7 @@
#include <sys/file.h>
#include <sys/wait.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <fcntl.h>
#ifdef HAVE_GETHOSTBYNAME
@@ -519,8 +520,27 @@ char **argv;
time(&now);
fprintf(stderr, "fetchmail: sleeping at %s", ctime(&now));
}
- if (sleep(poll_interval))
- (void) fputs("fetchmail: awakened by SIGHUP\n", stderr);
+
+ /*
+ * We can't use sleep(3) here, the alarm(2) call used to
+ * implement server nonresponse timeout collides with it.
+ * We'll just assume setitimer(2) is available since fetchmail
+ * has to have the socket layer to work at all.
+ */
+ {
+ struct itimerval ntimeout;
+
+ ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_sec = 0;
+ ntimeout.it_value.tv_sec = poll_interval;
+ ntimeout.it_value.tv_usec = 0;
+
+ if (setitimer(ITIMER_REAL,&ntimeout,(struct itimerval *)NULL)==-1
+ && errno == EINTR)
+ (void) fputs("fetchmail: awakened by SIGHUP\n", stderr);
+ signal(SIGALRM, donothing);
+ pause();
+ }
+
if (outlevel == O_VERBOSE)
{
time_t now;