From bc3c7ff7871fb949a6c5b408ab6af8a456ecba1d Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Thu, 1 Jan 2015 17:12:17 +0100 Subject: [PATCH] lib-sieve: Added more debug output to binary up-to-date checking. --- src/lib-sieve/sieve-binary.c | 24 ++++++++++++++++--- .../storage/file/sieve-file-script.c | 14 +++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/lib-sieve/sieve-binary.c b/src/lib-sieve/sieve-binary.c index 39f424b36..ed37ba8dc 100644 --- a/src/lib-sieve/sieve-binary.c +++ b/src/lib-sieve/sieve-binary.c @@ -315,22 +315,40 @@ bool sieve_binary_up_to_date struct sieve_binary_block *sblock; sieve_size_t offset = 0; unsigned int ext_count, i; + int ret; i_assert(sbin->file != NULL); sblock = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_SCRIPT_DATA); - if ( sblock == NULL || sbin->script == NULL || - sieve_script_binary_read_metadata(sbin->script, sblock, &offset) <= 0 ) + if ( sblock == NULL || sbin->script == NULL ) return FALSE; + if ( (ret=sieve_script_binary_read_metadata + (sbin->script, sblock, &offset)) <= 0 ) { + if (ret < 0) { + sieve_sys_debug(sbin->svinst, "binary up-to-date: " + "failed to read script metadata from binary %s", + sbin->path); + } else { + sieve_sys_debug(sbin->svinst, "binary up-to-date: " + "script metadata indicates that binary %s is not up-to-date", + sbin->path); + } + return FALSE; + } + regs = array_get(&sbin->extensions, &ext_count); for ( i = 0; i < ext_count; i++ ) { const struct sieve_binary_extension *binext = regs[i]->binext; if ( binext != NULL && binext->binary_up_to_date != NULL && !binext->binary_up_to_date - (regs[i]->extension, sbin, regs[i]->context, cpflags) ) + (regs[i]->extension, sbin, regs[i]->context, cpflags) ) { + sieve_sys_debug(sbin->svinst, "binary up-to-date: " + "the %s extension indicates binary %s is not up-to-date", + sieve_extension_name(regs[i]->extension), sbin->path); return FALSE; + } } return TRUE; diff --git a/src/lib-sieve/storage/file/sieve-file-script.c b/src/lib-sieve/storage/file/sieve-file-script.c index 027f7dbf9..b79adbd42 100644 --- a/src/lib-sieve/storage/file/sieve-file-script.c +++ b/src/lib-sieve/storage/file/sieve-file-script.c @@ -5,6 +5,7 @@ #include "mempool.h" #include "abspath.h" #include "istream.h" +#include "time-util.h" #include "eacces-error.h" #include "sieve-binary.h" @@ -475,12 +476,21 @@ static int sieve_file_script_binary_read_metadata sieve_size_t *offset ATTR_UNUSED) { struct sieve_file_script *fscript = (struct sieve_file_script *)script; + struct sieve_instance *svinst = script->storage->svinst; struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock); - time_t time = ( fscript->st.st_mtime > fscript->lnk_st.st_mtime ? + time_t bmtime = sieve_binary_mtime(sbin); + time_t smtime = ( fscript->st.st_mtime > fscript->lnk_st.st_mtime ? fscript->st.st_mtime : fscript->lnk_st.st_mtime ); - if ( sieve_binary_mtime(sbin) <= time ) + if ( bmtime <= smtime ) { + if (svinst->debug) { + sieve_script_sys_debug(script, + "Sieve binary is not newer than the Sieve script (%s <= %s)", + t_strflocaltime("%Y-%m-%d %H:%M:%S", bmtime), + t_strflocaltime("%Y-%m-%d %H:%M:%S", smtime)); + } return 0; + } return 1; } -- GitLab