Skip to content
Snippets Groups Projects
Unverified Commit 7e5f0fe1 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

gluon-web: clean up opening files

Open with O_CLOEXEC, use fstat() instead of stat().
parent 94f22e50
No related branches found
No related tags found
No related merge requests found
...@@ -74,10 +74,10 @@ static lmo_archive_t * lmo_open(const char *file) ...@@ -74,10 +74,10 @@ static lmo_archive_t * lmo_open(const char *file)
lmo_archive_t *ar = NULL; lmo_archive_t *ar = NULL;
if (stat(file, &s) == -1) if ((in = open(file, O_RDONLY|O_CLOEXEC)) == -1)
goto err; goto err;
if ((in = open(file, O_RDONLY)) == -1) if (fstat(in, &s) == -1)
goto err; goto err;
if ((ar = calloc(1, sizeof(*ar))) != NULL) { if ((ar = calloc(1, sizeof(*ar))) != NULL) {
...@@ -85,8 +85,6 @@ static lmo_archive_t * lmo_open(const char *file) ...@@ -85,8 +85,6 @@ static lmo_archive_t * lmo_open(const char *file)
ar->fd = in; ar->fd = in;
ar->size = s.st_size; 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) if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED)
goto err; goto err;
......
...@@ -45,10 +45,10 @@ struct template_parser * template_open(const char *file) ...@@ -45,10 +45,10 @@ struct template_parser * template_open(const char *file)
parser->fd = -1; parser->fd = -1;
parser->file = file; parser->file = file;
if (stat(file, &s)) if ((parser->fd = open(file, O_RDONLY|O_CLOEXEC)) < 0)
goto err; goto err;
if ((parser->fd = open(file, O_RDONLY)) < 0) if (fstat(parser->fd, &s))
goto err; goto err;
parser->size = s.st_size; parser->size = s.st_size;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment