Protect fsync() and close() from SIGALRM

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2019-11-27 21:08:00 +01:00
parent 34e25f6c74
commit 52e7e6293c
4 changed files with 13 additions and 4 deletions

View File

@ -66,8 +66,8 @@ listen_port=25
clamd_socket=/tmp/clamd
; check for client timeout interval. Default: 30 sec
check_for_client_timeout_interval=30
; check for client timeout interval. Default: 20 sec
check_for_client_timeout_interval=20
; smtp timeout. Default: 60 sec
smtp_timeout=60

View File

@ -62,7 +62,7 @@ struct _parse_rule config_parse_rules[] =
{ "archive_emails_not_having_message_id", "integer", (void*) int_parser, offsetof(struct config, archive_emails_not_having_message_id), "0", sizeof(int)},
{ "archive_only_mydomains", "integer", (void*) int_parser, offsetof(struct config, archive_only_mydomains), "0", sizeof(int)},
{ "backlog", "integer", (void*) int_parser, offsetof(struct config, backlog), "20", sizeof(int)},
{ "check_for_client_timeout_interval", "integer", (void*) int_parser, offsetof(struct config, check_for_client_timeout_interval), "30", sizeof(int)},
{ "check_for_client_timeout_interval", "integer", (void*) int_parser, offsetof(struct config, check_for_client_timeout_interval), "20", sizeof(int)},
{ "cipher_list", "string", (void*) string_parser, offsetof(struct config, cipher_list), "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS", MAXVAL-1},
{ "clamd_addr", "string", (void*) string_parser, offsetof(struct config, clamd_addr), "", MAXVAL-1},
{ "clamd_port", "integer", (void*) int_parser, offsetof(struct config, clamd_port), "0", sizeof(int)},

View File

@ -77,7 +77,7 @@ void __fatal(char *s){
}
/*
* calculate the difference betwwen two timevals in [usec]
* calculate the difference between two timevals in [usec]
*/
long tvdiff(struct timeval a, struct timeval b){

View File

@ -8,6 +8,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <syslog.h>
#include <signal.h>
#include <unistd.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@ -266,13 +267,21 @@ void process_command_data(struct smtp_session *session, struct config *cfg){
void process_command_period(struct smtp_session *session){
char buf[SMALLBUFSIZE];
struct timezone tz;
struct timeval tv1, tv2;
session->protocol_state = SMTP_STATE_PERIOD;
// TODO: add some error handling
sig_block(SIGALRM);
gettimeofday(&tv1, &tz);
fsync(session->fd);
close(session->fd);
gettimeofday(&tv2, &tz);
sig_unblock(SIGALRM);
syslog(LOG_PRIORITY, "fsync()+close() took %ld [us]", tvdiff(tv2, tv1));
session->fd = -1;