Skip to content

Commit

Permalink
Merge pull request #385 from WaryWolf/fix-job-creation-racecond
Browse files Browse the repository at this point in the history
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 36c230f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -19,6 +19,7 @@ Andreas Piesk
Andreas Rogge
Andreas Unterkircher
Andrew Ford
Anthony Vaccaro
Arno Lehmann
Aron Schüler
Attila Fülöp
Expand Down
4 changes: 3 additions & 1 deletion core/src/dird/job.cc
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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 = '_'; }
Expand Down

0 comments on commit 36c230f

Please sign in to comment.