]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Initialize StartTime in db_create_job_record()
authorEric Bollengier <eric@baculasystems.com>
Mon, 1 Feb 2021 10:20:02 +0000 (11:20 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 4 Feb 2021 14:53:26 +0000 (15:53 +0100)
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.

bacula/src/cats/sql_create.c

index 02c7e8a83b9745b149f4cb5274881217021d0c2a..1d8cdd835f2f7a60dc13f9b9ebca28e620644817 100644 (file)
@@ -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) {