From: Alan T. DeKok Date: Tue, 25 Jul 2017 13:52:01 +0000 (-0400) Subject: we always append to the file X-Git-Tag: release_3_0_16~202 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d4b6ca9fcf0b86afc7f5fa54b27dbb4c26932ae;p=thirdparty%2Ffreeradius-server.git we always append to the file --- diff --git a/src/include/exfile.h b/src/include/exfile.h index c511100603a..750eb4dd448 100644 --- a/src/include/exfile.h +++ b/src/include/exfile.h @@ -36,7 +36,7 @@ extern "C" { typedef struct exfile_t exfile_t; exfile_t *exfile_init(TALLOC_CTX *ctx, uint32_t entries, uint32_t idle, bool locking); -int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, bool append); +int exfile_open(exfile_t *lf, char const *filename, mode_t permissions); int exfile_close(exfile_t *lf, int fd); #ifdef __cplusplus diff --git a/src/main/exfile.c b/src/main/exfile.c index 245dee18a9e..f92d22934cc 100644 --- a/src/main/exfile.c +++ b/src/main/exfile.c @@ -205,10 +205,9 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi * @param ef The logfile context returned from exfile_init(). * @param filename the file to open. * @param permissions to use. - * @param append If true seek to the end of the file. * @return an FD used to write to the file, or -1 on error. */ -int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool append) +int exfile_open(exfile_t *ef, char const *filename, mode_t permissions) { int i, found, tries, unused, oldest; uint32_t hash; @@ -224,8 +223,7 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app found = exfile_open_mkdir(ef, filename, permissions); if (found < 0) return -1; - if (append) (void) lseek(found, 0, SEEK_END); - + (void) lseek(found, 0, SEEK_END); return found; } @@ -316,10 +314,15 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app reopen: /* - * Open the file and try to lock it. + * Open the file. */ ef->entries[i].fd = exfile_open_mkdir(ef, filename, permissions); - if (ef->entries[i].fd < 0) goto error; + if (ef->entries[i].fd < 0) { + error: + exfile_cleanup_entry(&ef->entries[i]); + PTHREAD_MUTEX_UNLOCK(&(ef->mutex)); + return -1; + } /* * Try to lock it. If we can't lock it, it's because @@ -336,11 +339,7 @@ reopen: */ if (lseek(ef->entries[i].fd, 0, SEEK_SET) < 0) { fr_strerror_printf("Failed to seek in file %s: %s", filename, strerror(errno)); - - error: - exfile_cleanup_entry(&ef->entries[i]); - PTHREAD_MUTEX_UNLOCK(&(ef->mutex)); - return -1; + goto error; } /* @@ -357,7 +356,7 @@ reopen: /* * Close the file and re-open it. It may * have been deleted. If it was deleted, - * then it should now be unlocked. + * then the new file should now be unlocked. */ close(ef->entries[i].fd); ef->entries[i].fd = open(filename, O_WRONLY | O_CREAT, permissions); @@ -391,7 +390,7 @@ reopen: * If we're appending, eek to the end of the file before * returning the FD to the caller. */ - if (append) lseek(ef->entries[i].fd, 0, SEEK_END); + (void) lseek(ef->entries[i].fd, 0, SEEK_END); /* * Return holding the mutex for the entry. diff --git a/src/modules/rlm_detail/rlm_detail.c b/src/modules/rlm_detail/rlm_detail.c index caa01749c06..20843a4fe63 100644 --- a/src/modules/rlm_detail/rlm_detail.c +++ b/src/modules/rlm_detail/rlm_detail.c @@ -388,7 +388,7 @@ static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request, #endif #endif - outfd = exfile_open(inst->ef, buffer, inst->perm, true); + outfd = exfile_open(inst->ef, buffer, inst->perm); if (outfd < 0) { RERROR("Couldn't open file %s: %s", buffer, fr_strerror()); return RLM_MODULE_FAIL; diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index 3d4219ca9ec..3c15bf04b30 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -248,7 +248,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ return RLM_MODULE_FAIL; } - fd = exfile_open(inst->ef, path, inst->permissions, true); + fd = exfile_open(inst->ef, path, inst->permissions); if (fd < 0) { ERROR("rlm_linelog: Failed to open %s: %s", path, fr_syserror(errno)); return RLM_MODULE_FAIL; diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 05d0bc24564..42759a75631 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -487,7 +487,7 @@ void rlm_sql_query_log(rlm_sql_t *inst, REQUEST *request, return; } - fd = exfile_open(inst->ef, filename, 0640, true); + fd = exfile_open(inst->ef, filename, 0640); if (fd < 0) { ERROR("rlm_sql (%s): Couldn't open logfile '%s': %s", inst->name, expanded, fr_syserror(errno));