if (timeout > 0)
{
sigalrm_seen = FALSE;
- alarm(timeout);
+ ALARM(timeout);
}
for(;;)
}
}
-if (timeout > 0) alarm(0);
+if (timeout > 0) ALARM_CLR(0);
signal(SIGCHLD, oldsignal); /* restore */
return yield;
}
sigalrm_seen = FALSE;
- alarm(resignal_interval);
+ ALARM(resignal_interval);
}
else
/* Reset the alarm clock */
sigalrm_seen = FALSE;
- alarm(queue_interval);
+ ALARM(queue_interval);
}
} /* sigalrm_seen */
getpid());
for (sk = 0; sk < listen_socket_count; sk++)
(void)close(listen_sockets[sk]);
- alarm(0);
+ ALARM_CLR(0);
signal(SIGHUP, SIG_IGN);
sighup_argv[0] = exim_path;
exim_nullstd();
debug_printf_indent("locking %s\n", filename);
sigalrm_seen = FALSE;
-alarm(EXIMDB_LOCK_TIMEOUT);
+ALARM(EXIMDB_LOCK_TIMEOUT);
rc = fcntl(dbblock->lockfd, F_SETLKW, &lock_data);
-alarm(0);
+ALARM_CLR(0);
if (sigalrm_seen) errno = ETIMEDOUT;
if (rc < 0)
sigalrm_handler(int sig)
{
sig = sig; /* Keep picky compilers happy */
-sigalrm_seen = 1;
+sigalrm_seen = TRUE;
}
sigalrm_seen = FALSE;
os_non_restarting_signal(SIGALRM, sigalrm_handler);
-alarm(EXIMDB_LOCK_TIMEOUT);
+ALARM(EXIMDB_LOCK_TIMEOUT);
rc = fcntl(dbblock->lockfd, F_SETLKW, &lock_data);
-alarm(0);
+ALARM_CLR(0);
if (sigalrm_seen) errno = ETIMEDOUT;
if (rc < 0)
server_name = US sockun.sun_path;
sigalrm_seen = FALSE;
- alarm(timeout);
+ ALARM(timeout);
rc = connect(fd, (struct sockaddr *)(&sockun), sizeof(sockun));
- alarm(0);
+ ALARM_CLR(0);
if (sigalrm_seen)
{
expand_string_message = US "socket connect timed out";
if (!tls_ctx)
fp = fdopen(fd, "rb");
sigalrm_seen = FALSE;
- alarm(timeout);
+ ALARM(timeout);
yield =
#ifdef SUPPORT_TLS
tls_ctx ? cat_file_tls(tls_ctx, yield, sub_arg[3]) :
#endif
cat_file(fp, yield, sub_arg[3]);
- alarm(0);
+ ALARM_CLR(0);
#ifdef SUPPORT_TLS
if (tls_ctx)
resetok = FALSE;
f = fdopen(fd_out, "rb");
sigalrm_seen = FALSE;
- alarm(60);
+ ALARM(60);
lookup_value = string_from_gstring(cat_file(f, NULL, NULL));
- alarm(0);
+ ALARM_CLR(0);
(void)fclose(f);
/* Wait for the process to finish, applying the timeout, and inspect its
uschar *sending_ip_address = NULL;
int sending_port = -1;
SIGNAL_BOOL sigalrm_seen = FALSE;
+const uschar *sigalarm_setter = NULL;
uschar **sighup_argv = NULL;
int slow_lookup_log = 0; /* millisecs, zero disables */
int smtp_accept_count = 0;
extern uschar *sending_ip_address; /* Address of outgoing (SMTP) interface */
extern int sending_port; /* Port of outgoing interface */
extern SIGNAL_BOOL sigalrm_seen; /* Flag for sigalrm_handler */
+extern const uschar *sigalarm_setter; /* For debug, set to callpoint of alarm() */
extern uschar **sighup_argv; /* Args for re-execing after SIGHUP */
extern int slow_lookup_log; /* Log DNS lookups taking longer than N millisecs */
extern int smtp_accept_count; /* Count of connections */
callout_address = string_sprintf("[%s]:%d", address, port);
sigalrm_seen = FALSE;
-if (timeout > 0) alarm(timeout);
+if (timeout > 0) ALARM(timeout);
#if defined(TCP_FASTOPEN) && defined(MSG_FASTOPEN)
/* TCP Fast Open, if the system has a cookie from a previous call to
}
save_errno = errno;
-alarm(0);
+ALARM_CLR(0);
/* There is a testing facility for simulating a connection timeout, as I
can't think of any other way of doing this. It converts a connection refused
#define TLS_SHUTDOWN_WAIT 2
+#ifdef COMPILE_UTILITY
+# define ALARM(seconds) alarm(seconds);
+# define ALARM_CLR(seconds) alarm(seconds);
+#else
+/* For debugging of odd alarm-signal problems, stash caller info while the
+alarm is active. Clear it down on cancelling the alarm so we can tell there
+should not be one active. */
+
+# define ALARM(seconds) \
+ debug_selector & D_any \
+ ? (sigalarm_setter = CCS __FUNCTION__, alarm(seconds)) : alarm(seconds);
+# define ALARM_CLR(seconds) \
+ debug_selector & D_any \
+ ? (sigalarm_setter = NULL, alarm(seconds)) : alarm(seconds);
+#endif
+
/* End of macros.h */
printf("Testing restarting signal; wait for handler message, then type a line\n");
strcpy(buffer, "*** default ***\n");
os_restarting_signal(SIGALRM, sigalrm_handler);
-alarm(2);
+ALARM(2);
if ((rc = read(fd, buffer, sizeof(buffer))) < 0)
printf("No data read\n");
else
buffer[rc] = 0;
printf("Read: %s", buffer);
}
-alarm(0);
+ALARM_CLR(0);
printf("Testing non-restarting signal; should read no data after handler message\n");
strcpy(buffer, "*** default ***\n");
os_non_restarting_signal(SIGALRM, sigalrm_handler);
-alarm(2);
+ALARM(2);
if ((rc = read(fd, buffer, sizeof(buffer))) < 0)
printf("No data read\n");
else
buffer[rc] = 0;
printf("Read: %s", buffer);
}
-alarm(0);
+ALARM_CLR(0);
printf("Testing load averages (last test - ^C to kill)\n");
for (;;)
slash = Ustrrchr(big_buffer, '/');
Ustrcpy(slash+1, ".");
- alarm(30);
+ ALARM(30);
rc = Ustat(big_buffer, &statbuf);
if (rc != 0 && errno == EACCES && !sigalrm_seen)
{
rc = Ustat(big_buffer, &statbuf);
}
saved_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
DEBUG(D_route) debug_printf("stat(%s)=%d\n", big_buffer, rc);
}
else if (receive_timeout > 0)
{
os_non_restarting_signal(SIGALRM, data_timeout_handler);
- alarm(receive_timeout);
+ ALARM(receive_timeout);
}
/* SIGTERM and SIGINT are caught always. */
had_local_scan_timeout = 0;
os_non_restarting_signal(SIGALRM, local_scan_timeout_handler);
- if (local_scan_timeout > 0) alarm(local_scan_timeout);
+ if (local_scan_timeout > 0) ALARM(local_scan_timeout);
rc = local_scan(data_fd, &local_scan_data);
- alarm(0);
+ ALARM_CLR(0);
os_non_restarting_signal(SIGALRM, sigalrm_handler);
f.enable_dollar_recipients = FALSE;
int rc, save_errno;
if (!smtp_out) return FALSE;
fflush(smtp_out);
-if (smtp_receive_timeout > 0) alarm(smtp_receive_timeout);
+if (smtp_receive_timeout > 0) ALARM(smtp_receive_timeout);
/* Limit amount read, so non-message data is not fed to DKIM.
Take care to not touch the safety NUL at the end of the buffer. */
rc = read(fileno(smtp_in), smtp_inbuffer, MIN(IN_BUFFER_SIZE-1, lim));
save_errno = errno;
-if (smtp_receive_timeout > 0) alarm(0);
+if (smtp_receive_timeout > 0) ALARM_CLR(0);
if (rc <= 0)
{
/* Must put the error text in fixed store, because this might be during
state->fd_out = fileno(smtp_out);
sigalrm_seen = FALSE;
-if (smtp_receive_timeout > 0) alarm(smtp_receive_timeout);
+if (smtp_receive_timeout > 0) ALARM(smtp_receive_timeout);
do
rc = gnutls_handshake(state->session);
while (rc == GNUTLS_E_AGAIN || rc == GNUTLS_E_INTERRUPTED && !sigalrm_seen);
-alarm(0);
+ALARM_CLR(0);
if (rc != GNUTLS_E_SUCCESS)
{
/* There doesn't seem to be a built-in timeout on connection. */
sigalrm_seen = FALSE;
-alarm(ob->command_timeout);
+ALARM(ob->command_timeout);
do
rc = gnutls_handshake(state->session);
while (rc == GNUTLS_E_AGAIN || rc == GNUTLS_E_INTERRUPTED && !sigalrm_seen);
-alarm(0);
+ALARM_CLR(0);
if (rc != GNUTLS_E_SUCCESS)
{
DEBUG(D_tls) debug_printf("tls_close(): shutting down TLS%s\n",
shutdown > 1 ? " (with response-wait)" : "");
- alarm(2);
+ ALARM(2);
gnutls_bye(state->session, shutdown > 1 ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
- alarm(0);
+ ALARM_CLR(0);
}
gnutls_deinit(state->session);
state->session, state->xfer_buffer, ssl_xfer_buffer_size);
sigalrm_seen = FALSE;
-if (smtp_receive_timeout > 0) alarm(smtp_receive_timeout);
+if (smtp_receive_timeout > 0) ALARM(smtp_receive_timeout);
inbytes = gnutls_record_recv(state->session, state->xfer_buffer,
MIN(ssl_xfer_buffer_size, lim));
-if (smtp_receive_timeout > 0) alarm(0);
+if (smtp_receive_timeout > 0) ALARM_CLR(0);
if (had_command_timeout) /* set by signal handler */
smtp_command_timeout_exit(); /* does not return */
DEBUG(D_tls) debug_printf("Calling SSL_accept\n");
sigalrm_seen = FALSE;
-if (smtp_receive_timeout > 0) alarm(smtp_receive_timeout);
+if (smtp_receive_timeout > 0) ALARM(smtp_receive_timeout);
rc = SSL_accept(server_ssl);
-alarm(0);
+ALARM_CLR(0);
if (rc <= 0)
{
DEBUG(D_tls) debug_printf("Calling SSL_connect\n");
sigalrm_seen = FALSE;
-alarm(ob->command_timeout);
+ALARM(ob->command_timeout);
rc = SSL_connect(exim_client_ctx->ssl);
-alarm(0);
+ALARM_CLR(0);
#ifdef SUPPORT_DANE
if (tlsa_dnsa)
DEBUG(D_tls) debug_printf("Calling SSL_read(%p, %p, %u)\n", server_ssl,
ssl_xfer_buffer, ssl_xfer_buffer_size);
-if (smtp_receive_timeout > 0) alarm(smtp_receive_timeout);
+if (smtp_receive_timeout > 0) ALARM(smtp_receive_timeout);
inbytes = SSL_read(server_ssl, CS ssl_xfer_buffer,
MIN(ssl_xfer_buffer_size, lim));
error = SSL_get_error(server_ssl, inbytes);
-if (smtp_receive_timeout > 0) alarm(0);
+if (smtp_receive_timeout > 0) ALARM_CLR(0);
if (had_command_timeout) /* set by signal handler */
smtp_command_timeout_exit(); /* does not return */
if ( (rc = SSL_shutdown(*sslp)) == 0 /* send "close notify" alert */
&& shutdown > 1)
{
- alarm(2);
+ ALARM(2);
rc = SSL_shutdown(*sslp); /* wait for response */
- alarm(0);
+ ALARM_CLR(0);
}
if (rc < 0) DEBUG(D_tls)
else
{
- alarm(local_timeout);
+ ALARM(local_timeout);
rc =
#ifdef SUPPORT_TLS
write(fd, block, len);
save_errno = errno;
- local_timeout = alarm(0);
+ local_timeout = ALARM_CLR(0);
if (sigalrm_seen)
{
errno = ETIMEDOUT;
for (;;)
{
sigalrm_seen = FALSE;
- alarm(transport_filter_timeout);
+ ALARM(transport_filter_timeout);
len = read(fd_read, deliver_in_buffer, DELIVER_IN_BUFFER_SIZE);
- alarm(0);
+ ALARM_CLR(0);
if (sigalrm_seen)
{
errno = ETIMEDOUT;
{
if (fcntltime > 0)
{
- alarm(fcntltime);
+ ALARM(fcntltime);
yield = fcntl(fd, F_SETLKW, &lock_data);
save_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
errno = save_errno;
}
else yield = fcntl(fd, F_SETLK, &lock_data);
int flocktype = (fcntltype == F_WRLCK) ? LOCK_EX : LOCK_SH;
if (flocktime > 0)
{
- alarm(flocktime);
+ ALARM(flocktime);
yield = flock(fd, flocktype);
save_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
errno = save_errno;
}
else yield = flock(fd, flocktype | LOCK_NB);
*readptr = 0; /* In case nothing gets read */
sigalrm_seen = FALSE;
- alarm(timeout);
+ ALARM(timeout);
rc = Ufgets(readptr, size-1, f);
save_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
errno = save_errno;
if (rc != NULL) break; /* A line has been read */
QUIT
200 OK
****
-exim -v -odi userx@test.ex
+exim -v -odi usery@test.ex
****