From 2d736705e72ea9259f49e10ec6a17f2bfd751318 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 15 Dec 2020 15:52:32 +0100 Subject: [PATCH] Fix #7168 About incorrect start time displayed for canceled jobs not yet running All the jobs that are canceled while they are still in the run queue (duplicate) are not reporting the start time correctly. Example: Scheduled time: 10-Dec-2020 13:15:01 Start time: 01-Jan-1970 01:00:00 End time: 10-Dec-2020 13:15:01 Elapsed time: 50 years 11 months 26 days 13 hours 15 mins 1 sec The fix will display an empty start time Scheduled time: 10-Dec-2020 13:15:01 Start time: End time: 10-Dec-2020 13:15:01 Elapsed time: 1 sec --- bacula/src/dird/admin.c | 6 +++--- bacula/src/dird/backup.c | 8 ++++---- bacula/src/dird/mac.c | 6 +++--- bacula/src/dird/restore.c | 6 +++--- bacula/src/dird/verify.c | 7 +++++-- bacula/src/lib/btime.c | 9 +++++++++ bacula/src/lib/btime.h | 1 + 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/bacula/src/dird/admin.c b/bacula/src/dird/admin.c index e05cb2af0..08f296cff 100644 --- a/bacula/src/dird/admin.c +++ b/bacula/src/dird/admin.c @@ -103,9 +103,9 @@ void admin_cleanup(JCR *jcr, int TermCode) sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus); break; } - bstrftimes(schedt, sizeof(schedt), jcr->jr.SchedTime); - bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); - bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); + bstrftimes_na(schedt, sizeof(schedt), jcr->jr.SchedTime); + bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n" diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 32ee45406..65d1ba054 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -983,11 +983,11 @@ void backup_cleanup(JCR *jcr, int TermCode) Mmsg(term_msg, _("Inappropriate term code: %c\n"), jcr->JobStatus); break; } - bstrftimes(schedt, sizeof(schedt), jcr->jr.SchedTime); - bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); - bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); + bstrftimes_na(schedt, sizeof(schedt), jcr->jr.SchedTime); + bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); RunTime = jcr->jr.EndTime - jcr->jr.StartTime; - if (RunTime <= 0) { + if (jcr->jr.StartTime == 0 || RunTime <= 0) { RunTime = 1; } kbps = ((double)jcr->jr.JobBytes) / (1000.0 * (double)RunTime); diff --git a/bacula/src/dird/mac.c b/bacula/src/dird/mac.c index d40d198ac..f49b8508e 100644 --- a/bacula/src/dird/mac.c +++ b/bacula/src/dird/mac.c @@ -869,10 +869,10 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode) } Mmsg(term_code, term_msg.c_str(), jcr->get_OperationName(), jcr->get_ActionName(0)); - bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); - bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); + bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); RunTime = jcr->jr.EndTime - jcr->jr.StartTime; - if (RunTime <= 0) { + if (jcr->jr.StartTime == 0 || RunTime <= 0) { RunTime = 1; } kbps = (double)jcr->SDJobBytes / (1000.0 * (double)RunTime); diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 0f2c058c3..f5e562ddb 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -703,11 +703,11 @@ void restore_cleanup(JCR *jcr, int TermCode) sprintf(term_code, _("Inappropriate term code: %c\n"), TermCode); break; } - bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); - bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); + bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); RunTime = jcr->jr.EndTime - jcr->jr.StartTime; - if (RunTime <= 0) { + if (jcr->jr.StartTime == 0 || RunTime <= 0) { RunTime = 1; } kbps = (double)jcr->jr.JobBytes / (1000.0 * (double)RunTime); diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index 6100255ef..287f584ba 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -496,9 +496,12 @@ void verify_cleanup(JCR *jcr, int TermCode) _("Inappropriate term code: %d %c\n"), TermCode, TermCode); break; } - bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); - bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); + bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); RunTime = jcr->jr.EndTime - jcr->jr.StartTime; + if (jcr->jr.StartTime == 0 || RunTime <= 0) { + RunTime = 1; + } if (jcr->verify_job) { Name = jcr->verify_job->hdr.name; } else { diff --git a/bacula/src/lib/btime.c b/bacula/src/lib/btime.c index 500204834..393301291 100644 --- a/bacula/src/lib/btime.c +++ b/bacula/src/lib/btime.c @@ -65,6 +65,15 @@ char *bstrftime(char *dt, int maxlen, utime_t utime) return dt; } +char *bstrftimes_na(char *dt, int maxlen, utime_t utime) +{ + if (utime == 0) { + return bstrncpy(dt, "", maxlen); + } else { + return bstrftimes(dt, maxlen, utime); + } +} + /* Formatted time for user display: dd-Mon-yyyy hh:mm:ss */ char *bstrftimes(char *dt, int maxlen, utime_t utime) { diff --git a/bacula/src/lib/btime.h b/bacula/src/lib/btime.h index 8a618d851..3e3579515 100644 --- a/bacula/src/lib/btime.h +++ b/bacula/src/lib/btime.h @@ -43,6 +43,7 @@ char *bstrftime_nc(char *dt, int maxlen, utime_t tim); char *bstrftime_dn(char *dt, int maxlen, utime_t tim); char *bstrftime_c(char *dt, int maxlen, utime_t utime); utime_t str_to_utime(char *str); +char *bstrftimes_na(char *dt, int maxlen, utime_t utime); /* =========================================================== */ -- 2.47.3