Skip to content

Commit 6b0b390

Browse files
authored
Merge pull request #2577 from pqarmitage/updates
don't overwrite track files at startup unless 'overwrite' specified
2 parents 087ad4a + fc53479 commit 6b0b390

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

keepalived/trackers/track_file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@
122122
/* Used for initialising track files */
123123
static enum {
124124
TRACK_FILE_NO_INIT,
125-
TRACK_FILE_CREATE,
126125
TRACK_FILE_INIT,
126+
TRACK_FILE_OVERWRITE,
127127
} track_file_init;
128128
static int track_file_init_value;
129129
static tracked_file_t *current_tf;
@@ -337,7 +337,7 @@ track_file_init_handler(const vector_t *strvec)
337337
const char *word;
338338
int value;
339339

340-
track_file_init = TRACK_FILE_CREATE;
340+
track_file_init = TRACK_FILE_INIT;
341341
track_file_init_value = 0;
342342

343343
for (i = 1; i < vector_size(strvec); i++) {
@@ -360,7 +360,7 @@ track_file_init_handler(const vector_t *strvec)
360360
track_file_init_value = value;
361361
}
362362
else if (!strcmp(word, "overwrite"))
363-
track_file_init = TRACK_FILE_INIT;
363+
track_file_init = TRACK_FILE_OVERWRITE;
364364
else
365365
report_config_error(CONFIG_GENERAL_ERROR, "Unknown track file init option %s", word);
366366
}
@@ -479,7 +479,7 @@ track_file_end_handler(void)
479479

480480
if (track_file_init != TRACK_FILE_NO_INIT) {
481481
ret = stat(track_file->file_path, &statb);
482-
if (!ret && track_file_init == TRACK_FILE_INIT) {
482+
if (!ret && track_file_init == TRACK_FILE_OVERWRITE) {
483483
if ((statb.st_mode & S_IFMT) != S_IFREG) {
484484
/* It is not a regular file */
485485
report_config_error(CONFIG_GENERAL_ERROR, "Cannot initialise track file %s"
@@ -494,7 +494,8 @@ track_file_end_handler(void)
494494
}
495495

496496
/* Don't overwrite a file on reload */
497-
if (!reload && !__test_bit(CONFIG_TEST_BIT, &debug)) {
497+
if (!reload && !__test_bit(CONFIG_TEST_BIT, &debug) &&
498+
(ret || track_file_init == TRACK_FILE_OVERWRITE)) { // the file doesn't exist or we want to overwrite it
498499
/* Write the value to the file */
499500
if ((tf = fopen_safe(track_file->file_path, "w"))) {
500501
fprintf(tf, "%d\n", track_file_init_value);

0 commit comments

Comments
 (0)