From 5cf1a46061ee1931753f4a13eec75cf65fd464b0 Mon Sep 17 00:00:00 2001 From: "R. Timothy Edwards" Date: Mon, 22 Jun 2026 21:52:06 -0400 Subject: [PATCH] Corrected two errors with the crash backup mechanism, one minor, one very major. The filename created had two slashes in the string ("/tmp//MAG...") because the temporary directory already has a slash in the string. This makes no practical difference but looks odd when printed to the terminal. The major error is that the Tcl script that re-establishes the timer after a backup had a typo that caused the timer never to be reset, resulting in crash backup files that are created and written once but never again. This egregious error has now finally been fixed. --- database/DBio.c | 5 +++-- tcltk/tools.tcl | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/database/DBio.c b/database/DBio.c index 82828907..770c9198 100644 --- a/database/DBio.c +++ b/database/DBio.c @@ -1145,7 +1145,8 @@ DBFileRecovery(filename) while ((dp = readdir(cwd)) != NULL) { char *doslash = (tempdir[strlen(tempdir) - 1] == '/') ? "" : "/"; - int n = snprintf(tempname, sizeof(tempname), "%s%s%s", tempdir, doslash, dp->d_name); + int n = snprintf(tempname, sizeof(tempname), "%s%s%s", tempdir, + doslash, dp->d_name); ASSERT(n < sizeof(tempname), "tempname"); snptr = tempname + strlen(tempdir); if (!strncmp(snptr, "MAG", 3)) @@ -5575,7 +5576,7 @@ DBWriteBackup(filename, archive, doforall) pid = (int)getpid(); doslash = (tempdir[strlen(tempdir) - 1] == '/') ? "" : "/"; - sprintf(template, "%s/MAG%d.XXXXXX", tempdir, pid); + sprintf(template, "%s%sMAG%d.XXXXXX", tempdir, doslash, pid); fd = mkstemp(template); if (fd == -1) diff --git a/tcltk/tools.tcl b/tcltk/tools.tcl index 27921bad..6cfc0089 100644 --- a/tcltk/tools.tcl +++ b/tcltk/tools.tcl @@ -57,11 +57,17 @@ proc magic::resumeall {} { proc magic::makecrashbackup {} { global Opts - *bypass crash save - if {![catch set Opts(backupinterval)]} { + if {[catch {*bypass crash save} errmsg]} { + puts stderr "Crash backup save error: $errmsg" + } + if {![catch {set Opts(backupinterval)}]} { if {$Opts(backupinterval) > 0} { after $Opts(backupinterval) magic::makecrashbackup + } else { + puts stderr "Warning: Crash backups halted due to interval of $Opts(backupinterval)" } + } else { + puts stderr "Warning: Crash backups halted due to no interval being set." } } @@ -88,7 +94,7 @@ proc magic::crashbackups {{option start}} { switch -exact $option { start { - if {[catch set Opts(backupinterval)]} { + if {[catch {set Opts(backupinterval)}]} { set Opts(backupinterval) 600000 } if {$Opts(backupinterval) > 0} { @@ -96,7 +102,7 @@ proc magic::crashbackups {{option start}} { } } resume { - if {![catch set Opts(backupinterval)]} { + if {![catch {set Opts(backupinterval)}]} { if {$Opts(backupinterval) > 0} { after $Opts(backupinterval) magic::makecrashbackup }