Skip to content

Commit 3c7754e

Browse files
committed
move fd management to narrower scope
and use fileno(fp), so that we have fewer concerns with managing the fd
1 parent 749a368 commit 3c7754e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/lib/server/cf_file.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
570570
cf_file_t *file;
571571
CONF_SECTION *top;
572572
fr_rb_tree_t *tree;
573-
int fd = -1;
574573
FILE *fp;
575574

576575
top = cf_root(cs);
@@ -585,7 +584,7 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
585584
if (from_dir) {
586585
cf_file_t my_file;
587586
char const *r;
588-
int my_fd;
587+
int fd, my_fd;
589588

590589
my_file.cs = cs;
591590
my_file.filename = filename;
@@ -626,14 +625,11 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
626625
fp = fdopen(fd, "r");
627626
} else {
628627
fp = fopen(filename, "r");
629-
if (fp) fd = fileno(fp);
630628
}
631629

632630
DEBUG2("including configuration file %s", filename);
633631

634-
if (!fp) {
635-
close(fd);
636-
632+
if (!fp) {
637633
error:
638634
ERROR("Unable to open file \"%s\": %s", filename, fr_syserror(errno));
639635
return -1;
@@ -645,7 +641,7 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
645641
file->cs = cs;
646642
file->from_dir = from_dir;
647643

648-
if (fstat(fd, &file->buf) == 0) {
644+
if (fstat(fileno(fp), &file->buf) == 0) {
649645
#ifdef S_IWOTH
650646
if ((file->buf.st_mode & S_IWOTH) != 0) {
651647
ERROR("Configuration file %s is globally writable. "

0 commit comments

Comments
 (0)