From: Alan T. DeKok Date: Sun, 15 Mar 2026 22:47:58 +0000 (-0400) Subject: move fd management to narrower scope X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3c7754e696a39fd4cc2f048d760f101f46ec6092;p=thirdparty%2Ffreeradius-server.git move fd management to narrower scope and use fileno(fp), so that we have fewer concerns with managing the fd --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 14c113ac85f..81da0a281c0 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -570,7 +570,6 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F cf_file_t *file; CONF_SECTION *top; fr_rb_tree_t *tree; - int fd = -1; FILE *fp; top = cf_root(cs); @@ -585,7 +584,7 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F if (from_dir) { cf_file_t my_file; char const *r; - int my_fd; + int fd, my_fd; my_file.cs = cs; my_file.filename = filename; @@ -626,14 +625,11 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F fp = fdopen(fd, "r"); } else { fp = fopen(filename, "r"); - if (fp) fd = fileno(fp); } DEBUG2("including configuration file %s", filename); - if (!fp) { - close(fd); - + if (!fp) { error: ERROR("Unable to open file \"%s\": %s", filename, fr_syserror(errno)); return -1; @@ -645,7 +641,7 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F file->cs = cs; file->from_dir = from_dir; - if (fstat(fd, &file->buf) == 0) { + if (fstat(fileno(fp), &file->buf) == 0) { #ifdef S_IWOTH if ((file->buf.st_mode & S_IWOTH) != 0) { ERROR("Configuration file %s is globally writable. "