* @param ef The logfile context returned from exfile_init().
* @param filename the file to open.
* @param permissions to use.
+ * @param offset Optional pointer to store offset in when seeking the end of file.
* @return
* - FD used to write to the file.
* - -1 on failure.
*/
-int exfile_open(exfile_t *ef, char const *filename, mode_t permissions)
+int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
{
int i, tries, unused = -1, found = -1, oldest = -1;
bool do_cleanup = false;
uint32_t hash;
fr_time_t now;
struct stat st;
+ off_t real_offset;
if (!ef || !filename) return -1;
found = exfile_open_mkdir(ef, filename, permissions);
if (found < 0) return -1;
- (void) lseek(found, 0, SEEK_END);
+ real_offset = lseek(found, 0, SEEK_END);
+ if (offset) *offset = real_offset;
return found;
}
* Seek to the end of the file before returning the FD to
* the caller.
*/
- (void) lseek(ef->entries[i].fd, 0, SEEK_END);
+ real_offset = lseek(ef->entries[i].fd, 0, SEEK_END);
+ if (offset) *offset = real_offset;
/*
* Return holding the mutex for the entry.
fr_pair_list_t *trigger_args);
CC_ACQUIRE_HANDLE("exfile_fd")
-int exfile_open(exfile_t *lf, char const *filename, mode_t permissions);
+int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, off_t *offset);
int exfile_close(exfile_t *lf, CC_RELEASE_HANDLE("exfile_fd") int fd);
RDEBUG2("%s expands to %s", inst->filename, buffer);
- outfd = exfile_open(inst->ef, buffer, inst->perm);
+ outfd = exfile_open(inst->ef, buffer, inst->perm, NULL);
if (outfd < 0) {
RPERROR("Couldn't open file %s", buffer);
RETURN_MODULE_FAIL;
*p = '/';
}
- fd = exfile_open(inst->file.ef, path, inst->file.permissions);
+ fd = exfile_open(inst->file.ef, path, inst->file.permissions, NULL);
if (fd < 0) {
RERROR("Failed to open %s: %s", path, fr_syserror(errno));
rcode = RLM_MODULE_FAIL;
return;
}
- fd = exfile_open(inst->ef, filename, 0640);
+ fd = exfile_open(inst->ef, filename, 0640, NULL);
if (fd < 0) {
ERROR("Couldn't open logfile '%s': %s", expanded, fr_syserror(errno));