]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
we always append to the file
authorAlan T. DeKok <aland@freeradius.org>
Tue, 25 Jul 2017 13:52:01 +0000 (09:52 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 25 Jul 2017 14:04:40 +0000 (10:04 -0400)
src/include/exfile.h
src/main/exfile.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_sql/sql.c

index c511100603a3e699dccc4f7e9f648e153e87ce7b..750eb4dd448f4139fd4eaf678d3da9676dc03304 100644 (file)
@@ -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
index 245dee18a9e9b68efeba4275e1fe7caef1f6680c..f92d22934cce58040f250ca057bfb0fd664aec70 100644 (file)
@@ -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.
index caa01749c06faacc345ab021d36eaabe577e5be7..20843a4fe63f53be9b1cae1daa6e63ded2d2041c 100644 (file)
@@ -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;
index 3d4219ca9ec21594e6c2c8b3d0d38f23187b95bb..3c15bf04b309da384df5acdf871a8c9c5cbea47c 100644 (file)
@@ -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;
index 05d0bc245643e26a2f39aa30e24c5b6609d8c10c..42759a7563197c7113d63d63998d44e2f31f9d0f 100644 (file)
@@ -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));