Skip to content
Permalink
Browse files

Merge pull request #385 from WaryWolf/fix-job-creation-racecond

copy value of seq to the stack to avoid race condition when generating Job names
  • Loading branch information
franku committed Jan 3, 2020
1 parent 790d442 commit 36c230fa9435cdeff4c069ec6db3d148f53ef3fe
Showing with 4 additions and 1 deletion.
  1. +1 −0 AUTHORS
  2. +3 −1 core/src/dird/job.cc
@@ -19,6 +19,7 @@ Andreas Piesk
Andreas Rogge
Andreas Unterkircher
Andrew Ford
Anthony Vaccaro
Arno Lehmann
Aron Schüler
Attila Fülöp
@@ -1506,6 +1506,7 @@ void CreateUniqueJobName(JobControlRecord* jcr, const char* base_name)
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static time_t last_start_time = 0;
static int seq = 0;
int lseq = 0;
time_t now = time(NULL);
char dt[MAX_TIME_LENGTH];
char name[MAX_NAME_LENGTH];
@@ -1524,6 +1525,7 @@ void CreateUniqueJobName(JobControlRecord* jcr, const char* base_name)
now = time(NULL);
}
}
lseq = seq;
last_start_time = now;
V(mutex); /* allow creation of jobs */
jcr->start_time = now;
@@ -1538,7 +1540,7 @@ void CreateUniqueJobName(JobControlRecord* jcr, const char* base_name)
bstrncpy(name, base_name, sizeof(name));
name[sizeof(name) - len] = 0; /* truncate if too long */
Bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s_%02d", name, dt,
seq); /* add date & time */
lseq); /* add date & time */
/* Convert spaces into underscores */
for (p = jcr->Job; *p; p++) {
if (*p == ' ') { *p = '_'; }

0 comments on commit 36c230f

Please sign in to comment.
You can’t perform that action at this time.