From: Eric Bollengier Date: Mon, 1 Feb 2021 10:20:02 +0000 (+0100) Subject: Initialize StartTime in db_create_job_record() X-Git-Tag: Release-11.3.2~765 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec38c89da8f264789c46415bf07a65afd7d928ef;p=thirdparty%2Fbacula.git Initialize StartTime in db_create_job_record() We initialize the StarTime DB field earlier in db_create_job_record() to avoid strange behaviors when the job is canceled before the actual start of the job. When the StartTime field is NULL, the "list jobs" is incorrect, the job output is also incorrect. --- diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index ff4ac4eae..166fb53f8 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -45,8 +45,8 @@ static const int dbglevel = 100; bool BDB::bdb_create_job_record(JCR *jcr, JOB_DBR *jr) { POOL_MEM buf; - char dt[MAX_TIME_LENGTH]; - time_t stime; + char dt[MAX_TIME_LENGTH], dt2[MAX_TIME_LENGTH]; + time_t stime, starttime; struct tm tm; bool ok; int len; @@ -58,10 +58,14 @@ bool BDB::bdb_create_job_record(JCR *jcr, JOB_DBR *jr) bdb_lock(); stime = jr->SchedTime; + starttime = jr->StartTime; ASSERT(stime != 0); (void)localtime_r(&stime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); + + (void)localtime_r(&starttime, &tm); + strftime(dt2, sizeof(dt2), "%Y-%m-%d %H:%M:%S", &tm); JobTDate = (utime_t)stime; len = strlen(jcr->comment); /* TODO: use jr instead of jcr to get comment */ @@ -73,11 +77,11 @@ bool BDB::bdb_create_job_record(JCR *jcr, JOB_DBR *jr) /* Must create it */ Mmsg(cmd, -"INSERT INTO Job (Job,Name,Type,Level,JobStatus,SchedTime,JobTDate," +"INSERT INTO Job (Job,Name,Type,Level,JobStatus,StartTime,SchedTime,JobTDate," "ClientId,Comment) " -"VALUES ('%s','%s','%c','%c','%c','%s',%s,%s,'%s')", +"VALUES ('%s','%s','%c','%c','%c','%s','%s',%s,%s,'%s')", esc_job, esc_name, (char)(jr->JobType), (char)(jr->JobLevel), - (char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1), + (char)(jr->JobStatus), dt2, dt, edit_uint64(JobTDate, ed1), edit_int64(jr->ClientId, ed2), buf.c_str()); if ((jr->JobId = sql_insert_autokey_record(cmd, NT_("Job"))) == 0) {