Skip to content

Commit f5c39e3

Browse files
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
Signed-off-by: ethan-thompson <ethan.thompson@networkradius.com>
1 parent 06add39 commit f5c39e3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib/server/exfile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
241241

242242
fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
243243
if (fd < 0) {
244+
int dirfd;
244245
mode_t dirperm;
245246
char *p, *dir;
246247

@@ -267,14 +268,15 @@ static int exfile_open_mkdir(exfile_t *ef, char const *filename, mode_t permissi
267268
if ((dirperm & 0060) != 0) dirperm |= 0010;
268269
if ((dirperm & 0006) != 0) dirperm |= 0001;
269270

270-
if (fr_mkdir(NULL, dir, -1, dirperm, NULL, NULL) < 0) {
271+
if (fr_mkdir(&dirfd, dir, -1, dirperm, NULL, NULL) < 0) {
271272
fr_strerror_printf("Failed to create directory %s: %s", dir, fr_syserror(errno));
272273
talloc_free(dir);
273274
return -1;
274275
}
275276
talloc_free(dir);
276277

277-
fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
278+
fd = openat(dirfd, p+1, O_RDWR | O_CREAT | flags, permissions);
279+
close(dirfd);
278280
if (fd < 0) {
279281
fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
280282
return -1;

0 commit comments

Comments
 (0)