From c5b81ab8ec4a4f709a1ed850728b4b6bc93fa35f Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Mon, 29 Jan 2024 00:18:32 +0000 Subject: [PATCH] Flush debug-file more often Instead of only flushing/unlocking the debug file at the end of the run, flush after each write, aligning it with the outfile and potfile's behaviour --- src/debugfile.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/debugfile.c b/src/debugfile.c index 20ee3ad1f..ea0d61365 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -76,6 +76,11 @@ void debugfile_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *rule_buf, con if ((debug_mode == 3) || (debug_mode == 4) || (debug_mode == 5)) hc_fputc (':', &debugfile_ctx->fp); } + if (hc_lockfile (&debugfile_ctx->fp) == -1) + { + event_log_error (hashcat_ctx, "%s: Failed to lock file.", debugfile_ctx->filename); + } + hc_fwrite (rule_buf, rule_len, 1, &debugfile_ctx->fp); if ((debug_mode == 4) || (debug_mode == 5)) @@ -104,6 +109,13 @@ void debugfile_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *rule_buf, con } hc_fwrite (EOL, strlen (EOL), 1, &debugfile_ctx->fp); + + hc_fflush (&debugfile_ctx->fp); + + if (hc_unlockfile (&debugfile_ctx->fp)) + { + event_log_error (hashcat_ctx, "%s: Failed to unlock file.", debugfile_ctx->filename); + } } int debugfile_init (hashcat_ctx_t *hashcat_ctx) @@ -150,15 +162,6 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx) return -1; } - if (hc_lockfile (&debugfile_ctx->fp) == -1) - { - hc_fclose (&debugfile_ctx->fp); - - event_log_error (hashcat_ctx, "%s: %s", debugfile_ctx->filename, strerror (errno)); - - return -1; - } - return 0; }