From 52e7e6293c12f7d223091a8840ce4c8a8c96cb52 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Wed, 27 Nov 2019 21:08:00 +0100 Subject: [PATCH] Protect fsync() and close() from SIGALRM Signed-off-by: Janos SUTO --- etc/example.conf | 4 ++-- src/cfg.c | 2 +- src/misc.c | 2 +- src/smtp.c | 9 +++++++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/etc/example.conf b/etc/example.conf index 739a236c..c002a15d 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -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 diff --git a/src/cfg.c b/src/cfg.c index a49cf16a..7734d985 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -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)}, diff --git a/src/misc.c b/src/misc.c index 89a72a17..2e107227 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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){ diff --git a/src/smtp.c b/src/smtp.c index 6f77cdae..484c4172 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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;