Skip to content

Commit 3d1f72c

Browse files
feat: Added the inflags parameter to exfile_open to allow for flags to be passed to open(2).
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
1 parent 8ad61b8 commit 3d1f72c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/lib/server/exfile.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ void exfile_enable_triggers(exfile_t *ef, CONF_SECTION *conf, char const *trigge
232232
* Try to open the file. It it doesn't exist, try to
233233
* create it's parent directories.
234234
*/
235-
static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissions)
235+
static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissions, int inflags)
236236
{
237237
int fd;
238238

239-
fd = open(filename, O_RDWR | O_CREAT, permissions);
239+
fd = open(filename, inflags, permissions);
240240
if (fd < 0) {
241241
mode_t dirperm;
242242
char *p, *dir;
@@ -271,7 +271,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
271271
}
272272
talloc_free(dir);
273273

274-
fd = open(filename, O_RDWR | O_CREAT, permissions);
274+
fd = open(filename, inflags, permissions);
275275
if (fd < 0) {
276276
fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
277277
return -1;
@@ -286,7 +286,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
286286
* to influence whether and which __coverity*__() functions are called. We therefore create a
287287
* separate function for the locking case which we *can* model.
288288
*/
289-
static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
289+
static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissions, int inflags, off_t *offset)
290290
{
291291
int i, tries, unused = -1, found = -1, oldest = -1;
292292
bool do_cleanup = false;
@@ -399,7 +399,7 @@ static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissio
399399
ef->entries[i].fd = -1;
400400

401401
reopen:
402-
ef->entries[i].fd = exfile_open_mkdir(ef, filename, permissions);
402+
ef->entries[i].fd = exfile_open_mkdir(ef, filename, permissions, inflags);
403403
if (ef->entries[i].fd < 0) goto error;
404404

405405
exfile_trigger(ef, &ef->entries[i], EXFILE_TRIGGER_OPEN);
@@ -432,7 +432,7 @@ static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissio
432432
}
433433

434434
close(ef->entries[i].fd);
435-
ef->entries[i].fd = open(filename, O_RDWR | O_CREAT, permissions);
435+
ef->entries[i].fd = open(filename, inflags, permissions);
436436
if (ef->entries[i].fd < 0) {
437437
fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
438438
goto error;
@@ -518,17 +518,18 @@ static int exfile_open_lock(exfile_t *ef, char const *filename, mode_t permissio
518518
* @param ef The logfile context returned from exfile_init().
519519
* @param filename the file to open.
520520
* @param permissions to use.
521+
* @param inflags flags to pass to open.
521522
* @param offset Optional pointer to store offset in when seeking the end of file.
522523
* @return
523524
* - FD used to write to the file.
524525
* - -1 on failure.
525526
*/
526-
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
527+
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, int inflags, off_t *offset)
527528
{
528529
if (!ef || !filename) return -1;
529530

530531
if (!ef->locking) {
531-
int found = exfile_open_mkdir(ef, filename, permissions);
532+
int found = exfile_open_mkdir(ef, filename, permissions, inflags);
532533
off_t real_offset;
533534

534535
if (found < 0) return -1;
@@ -537,7 +538,7 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *o
537538
return found;
538539
}
539540

540-
return exfile_open_lock(ef, filename, permissions, offset);
541+
return exfile_open_lock(ef, filename, permissions, inflags, offset);
541542
}
542543

543544
/*

src/lib/server/exfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void exfile_enable_triggers(exfile_t *ef, CONF_SECTION *cs, char const *trigger
4141
fr_pair_list_t *trigger_args);
4242

4343
CC_ACQUIRE_HANDLE("exfile_fd")
44-
int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, off_t *offset);
44+
int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, int inflags, off_t *offset);
4545

4646
int exfile_close(exfile_t *lf, CC_RELEASE_HANDLE("exfile_fd") int fd);
4747

0 commit comments

Comments
 (0)