Skip to content

Commit 46de8d1

Browse files
feat: Added the flags parameter to allow for flags to be passed to open(2).
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
1 parent 42a80b0 commit 46de8d1

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
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 flags)
236236
{
237237
int fd;
238238

239-
fd = open(filename, O_RDWR | O_CREAT, permissions);
239+
fd = open(filename, O_RDWR | O_CREAT | flags, 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, O_RDWR | O_CREAT | flags, 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 flags, 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, flags);
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, O_RDWR | O_CREAT | flags, 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 flags 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 flags, 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, flags);
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, flags, 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 flags, off_t *offset);
4545

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

src/modules/rlm_detail/rlm_detail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static unlang_action_t CC_HINT(nonnull) detail_do(unlang_result_t *p_result, mod
319319

320320
RDEBUG2("%s expands to %pV", env->filename_tmpl->name, &env->filename);
321321

322-
outfd = exfile_open(inst->ef, env->filename.vb_strvalue, inst->perm, NULL);
322+
outfd = exfile_open(inst->ef, env->filename.vb_strvalue, inst->perm, 0, NULL);
323323
if (outfd < 0) {
324324
RPERROR("Couldn't open file %pV", &env->filename);
325325

src/modules/rlm_linelog/rlm_linelog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static int linelog_write(rlm_linelog_t const *inst, linelog_call_env_t const *ca
405405
*p = '/';
406406
}
407407

408-
fd = exfile_open(inst->file.ef, path, inst->file.permissions, &offset);
408+
fd = exfile_open(inst->file.ef, path, inst->file.permissions, 0, &offset);
409409
if (fd < 0) {
410410
RERROR("Failed to open %pV: %s", call_env->filename, fr_syserror(errno));
411411

src/modules/rlm_sql/sql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *
389389
size_t len;
390390
bool failed = false; /* Write the log message outside of the critical region */
391391

392-
fd = exfile_open(inst->ef, filename, 0640, NULL);
392+
fd = exfile_open(inst->ef, filename, 0640, 0, NULL);
393393
if (fd < 0) {
394394
ERROR("Couldn't open logfile '%s': %s", filename, fr_syserror(errno));
395395

0 commit comments

Comments
 (0)