From: Ethan Thompson <77711716+ethan-thompson@users.noreply.github.com> Date: Fri, 6 Feb 2026 01:30:37 +0000 (-0500) Subject: fix: Use the more optimized openat method to open a directory since we already can... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9ba8f8b16d083c2d83600dc1492970bb188c2d0;p=thirdparty%2Ffreeradius-server.git fix: Use the more optimized openat method to open a directory since we already can get the fd from a previous mkdir call. Also close the directory fd as we use them, since we no longer need them to be open (#5737) Signed-off-by: ethan-thompson --- diff --git a/src/lib/server/exfile.c b/src/lib/server/exfile.c index 1d3826b5ddb..63f77cc40e3 100644 --- a/src/lib/server/exfile.c +++ b/src/lib/server/exfile.c @@ -241,6 +241,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi fd = open(filename, O_RDWR | O_CREAT | flags, permissions); if (fd < 0) { + int dirfd; mode_t dirperm; char *p, *dir; @@ -267,14 +268,15 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi if ((dirperm & 0060) != 0) dirperm |= 0010; if ((dirperm & 0006) != 0) dirperm |= 0001; - if (fr_mkdir(NULL, dir, -1, dirperm, NULL, NULL) < 0) { + if (fr_mkdir(&dirfd, dir, -1, dirperm, NULL, NULL) < 0) { fr_strerror_printf("Failed to create directory %s: %s", dir, fr_syserror(errno)); talloc_free(dir); return -1; } talloc_free(dir); - fd = open(filename, O_RDWR | O_CREAT | flags, permissions); + fd = openat(dirfd, p+1, O_RDWR | O_CREAT | flags, permissions); + close(dirfd); if (fd < 0) { fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno)); return -1;