* Local static variables *
*************************************************/
-static FILE *data_file = NULL;
static int data_fd = -1;
static uschar *spool_name = US"";
/* Now close the file if it is open, either as a fd or a stream. */
-if (data_file)
+if (spool_data_file)
{
- (void)fclose(data_file);
- data_file = NULL;
+ (void)fclose(spool_data_file);
+ spool_data_file = NULL;
}
else if (data_fd >= 0)
{
{
recipients_count = 0;
*blackholed_by_ptr = US"MIME ACL";
+ cancel_cutthrough_connection(TRUE, US"mime acl discard");
}
else if (rc != OK)
{
Uunlink(spool_name);
+ cancel_cutthrough_connection(TRUE, US"mime acl not ok");
unspool_mbox();
#ifdef EXPERIMENTAL_DCC
dcc_ok = 0;
yet, initialize the size and warning count, and deal with no size limit. */
message_id[0] = 0;
-data_file = NULL;
+spool_data_file = NULL;
data_fd = -1;
spool_name = US"";
message_size = 0;
are problems when Exim is run under Cygwin (I'm told). See comments in
spool_in.c, where the same locking is done. */
-data_file = fdopen(data_fd, "w+");
+spool_data_file = fdopen(data_fd, "w+");
lock_data.l_type = F_WRLCK;
lock_data.l_whence = SEEK_SET;
lock_data.l_start = 0;
format); write it (remembering that it might contain binary zeros). The result
of fwrite() isn't inspected; instead we call ferror() below. */
-fprintf(data_file, "%s-D\n", message_id);
+fprintf(spool_data_file, "%s-D\n", message_id);
if (next)
{
uschar *s = next->text;
int len = next->slen;
- if (fwrite(s, 1, len, data_file) == len) /* "if" for compiler quietening */
+ if (fwrite(s, 1, len, spool_data_file) == len) /* "if" for compiler quietening */
body_linecount++; /* Assumes only 1 line */
}
(indicated by '.'), or might have encountered an error while writing the
message id or "next" line. */
-if (!ferror(data_file) && !(receive_feof)() && message_ended != END_DOT)
+if (!ferror(spool_data_file) && !(receive_feof)() && message_ended != END_DOT)
{
if (smtp_input)
{
message_ended = chunking_state <= CHUNKING_OFFERED
- ? read_message_data_smtp(data_file)
+ ? read_message_data_smtp(spool_data_file)
: spool_wireformat
- ? read_message_bdat_smtp_wire(data_file)
- : read_message_bdat_smtp(data_file);
+ ? read_message_bdat_smtp_wire(spool_data_file)
+ : read_message_bdat_smtp(spool_data_file);
receive_linecount++; /* The terminating "." line */
}
else
- message_ended = read_message_data(data_file);
+ message_ended = read_message_data(spool_data_file);
receive_linecount += body_linecount; /* For BSMTP errors mainly */
message_linecount += body_linecount;
}
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
give_local_error(ERRMESS_TOOBIG,
string_sprintf("message too big (max=%d)", thismessage_size_limit),
- US"message rejected: ", error_rc, data_file, header_list);
+ US"message rejected: ", error_rc, spool_data_file, header_list);
/* Does not return */
}
break;
the input in cases of output errors, since the far end doesn't expect to see
anything until the terminating dot line is sent. */
-if (fflush(data_file) == EOF || ferror(data_file) ||
- EXIMfsync(fileno(data_file)) < 0 || (receive_ferror)())
+if (fflush(spool_data_file) == EOF || ferror(spool_data_file) ||
+ EXIMfsync(fileno(spool_data_file)) < 0 || (receive_ferror)())
{
uschar *msg_errno = US strerror(errno);
BOOL input_error = (receive_ferror)() != 0;
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
- give_local_error(ERRMESS_IOERR, msg, US"", error_rc, data_file,
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ give_local_error(ERRMESS_IOERR, msg, US"", error_rc, spool_data_file,
header_list);
/* Does not return */
}
}
}
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
/* If configured to send errors to the sender, but this fails, force
a failure error code. We use a special one for no recipients so that it
(bad_addresses == NULL)?
(extracted_ignored? ERRMESS_IGADDRESS : ERRMESS_NOADDRESS) :
(recipients_list == NULL)? ERRMESS_BADNOADDRESS : ERRMESS_BADADDRESS,
- bad_addresses, header_list, data_file, FALSE))
+ bad_addresses, header_list, spool_data_file, FALSE))
error_rc = (bad_addresses == NULL)? EXIT_NORECIPIENTS : EXIT_FAILURE;
}
else
if (recipients_count == 0 || error_handling == ERRORS_STDERR)
{
Uunlink(spool_name);
- (void)fclose(data_file);
+ (void)fclose(spool_data_file);
exim_exit(error_rc, US"receiving");
}
}
/* Does not return */
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
give_local_error(ERRMESS_LOCAL_ACL, user_msg,
- US"message rejected by non-SMTP ACL: ", error_rc, data_file,
+ US"message rejected by non-SMTP ACL: ", error_rc, spool_data_file,
header_list);
/* Does not return */
}
}
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
give_local_error(ERRMESS_LOCAL_SCAN, errmsg,
- US"message rejected by local scan code: ", error_rc, data_file,
+ US"message rejected by local scan code: ", error_rc, spool_data_file,
header_list);
/* Does not return */
}
}
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
- give_local_error(ERRMESS_IOERR, errmsg, US"", error_rc, data_file,
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ give_local_error(ERRMESS_IOERR, errmsg, US"", error_rc, spool_data_file,
header_list);
/* Does not return */
}
precedes the data. This total differs from message_size in that it include the
added Received: header and any other headers that got created locally. */
-if (fflush(data_file))
+if (fflush(spool_data_file))
{
errmsg = string_sprintf("Spool write error: %s", strerror(errno));
log_write(0, LOG_MAIN, "%s\n", errmsg);
}
else
{
- fseek(data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
- give_local_error(ERRMESS_IOERR, errmsg, US"", error_rc, data_file,
+ fseek(spool_data_file, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
+ give_local_error(ERRMESS_IOERR, errmsg, US"", error_rc, spool_data_file,
header_list);
/* Does not return */
}
TIDYUP:
process_info[process_info_len] = 0; /* Remove message id */
-if (data_file && cutthrough_done == NOT_TRIED)
- if (fclose(data_file)) /* Frees the lock */
+if (spool_data_file && cutthrough_done == NOT_TRIED)
+ {
+ if (fclose(spool_data_file)) /* Frees the lock */
log_write(0, LOG_MAIN|LOG_PANIC,
"spoolfile error on close: %s", strerror(errno));
+ spool_data_file = NULL;
+ }
/* Now reset signal handlers to their defaults */
}
if (cutthrough_done != NOT_TRIED)
{
- if (data_file)
- (void) fclose(data_file); /* Frees the lock; do not care if error */
+ if (spool_data_file)
+ {
+ (void) fclose(spool_data_file); /* Frees the lock; do not care if error */
+ spool_data_file = NULL;
+ }
message_id[0] = 0; /* Prevent a delivery from starting */
cutthrough.delivery = cutthrough.callout_hold_only = FALSE;
cutthrough.defer_pass = FALSE;
uschar buffer[16384];
uschar *temp_string;
uschar *mbox_path;
-FILE *mbox_file = NULL;
-FILE *data_file = NULL;
-FILE *yield = NULL;
+FILE *mbox_file = NULL, *l_data_file = NULL, *yield = NULL;
header_line *my_headerlist;
struct stat statbuf;
int i, j;
goto OUT;
}
- /* copy body file */
- if (!source_file_override)
+ /* Copy body file. If the main receive still has it open then it is holding
+ a lock, and we must not close it (which releases the lock), so just use the
+ global file handle. */
+ if (source_file_override)
+ l_data_file = Ufopen(source_file_override, "rb");
+ else if (spool_data_file)
+ l_data_file = spool_data_file;
+ else
{
message_subdir[1] = '\0';
for (i = 0; i < 2; i++)
{
message_subdir[0] = split_spool_directory == (i == 0) ? message_id[5] : 0;
temp_string = spool_fname(US"input", message_subdir, message_id, US"-D");
- if ((data_file = Ufopen(temp_string, "rb"))) break;
+ if ((l_data_file = Ufopen(temp_string, "rb"))) break;
}
}
- else
- data_file = Ufopen(source_file_override, "rb");
- if (!data_file)
+ if (!l_data_file)
{
log_write(0, LOG_MAIN|LOG_PANIC, "Could not open datafile for message %s",
message_id);
/* The code used to use this line, but it doesn't work in Cygwin.
- (void)fread(data_buffer, 1, 18, data_file);
+ (void)fread(data_buffer, 1, 18, l_data_file);
What's happening is that spool_mbox used to use an fread to jump over the
file header. That fails under Cygwin because the header is locked, but
explicitly, because the one in the file is parted of the locked area. */
if (!source_file_override)
- (void)fseek(data_file, SPOOL_DATA_START_OFFSET, SEEK_SET);
+ (void)fseek(l_data_file, SPOOL_DATA_START_OFFSET, SEEK_SET);
do
{
uschar * s;
if (!spool_file_wireformat || source_file_override)
- j = fread(buffer, 1, sizeof(buffer), data_file);
+ j = fread(buffer, 1, sizeof(buffer), l_data_file);
else /* needs CRLF -> NL */
- if ((s = US fgets(CS buffer, sizeof(buffer), data_file)))
+ if ((s = US fgets(CS buffer, sizeof(buffer), l_data_file)))
{
uschar * p = s + Ustrlen(s) - 1;
if (*p == '\n' && p[-1] == '\r')
*--p = '\n';
else if (*p == '\r')
- ungetc(*p--, data_file);
+ ungetc(*p--, l_data_file);
j = p - buffer;
}
*mbox_file_size = statbuf.st_size;
OUT:
-if (data_file) (void)fclose(data_file);
+if (l_data_file && !spool_data_file) (void)fclose(l_data_file);
if (mbox_file) (void)fclose(mbox_file);
store_reset(reset_point);
return yield;