From 7e5f0fe1d5d358e9208cb37d7a92110574d1730e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 22 Feb 2018 14:18:24 +0100 Subject: [PATCH] gluon-web: clean up opening files Open with O_CLOEXEC, use fstat() instead of stat(). --- package/gluon-web/src/template_lmo.c | 6 ++---- package/gluon-web/src/template_parser.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package/gluon-web/src/template_lmo.c b/package/gluon-web/src/template_lmo.c index 94ebd123..42881d6e 100644 --- a/package/gluon-web/src/template_lmo.c +++ b/package/gluon-web/src/template_lmo.c @@ -74,10 +74,10 @@ static lmo_archive_t * lmo_open(const char *file) lmo_archive_t *ar = NULL; - if (stat(file, &s) == -1) + if ((in = open(file, O_RDONLY|O_CLOEXEC)) == -1) goto err; - if ((in = open(file, O_RDONLY)) == -1) + if (fstat(in, &s) == -1) goto err; if ((ar = calloc(1, sizeof(*ar))) != NULL) { @@ -85,8 +85,6 @@ static lmo_archive_t * lmo_open(const char *file) ar->fd = in; ar->size = s.st_size; - fcntl(ar->fd, F_SETFD, fcntl(ar->fd, F_GETFD) | FD_CLOEXEC); - if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED) goto err; diff --git a/package/gluon-web/src/template_parser.c b/package/gluon-web/src/template_parser.c index 4f3ad15f..2c5379f7 100644 --- a/package/gluon-web/src/template_parser.c +++ b/package/gluon-web/src/template_parser.c @@ -45,10 +45,10 @@ struct template_parser * template_open(const char *file) parser->fd = -1; parser->file = file; - if (stat(file, &s)) + if ((parser->fd = open(file, O_RDONLY|O_CLOEXEC)) < 0) goto err; - if ((parser->fd = open(file, O_RDONLY)) < 0) + if (fstat(parser->fd, &s)) goto err; parser->size = s.st_size;