gluon-web: clean up opening files
Open with O_CLOEXEC, use fstat() instead of stat().
This commit is contained in:
parent
94f22e50e6
commit
7e5f0fe1d5
@ -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)
|
|||||||
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)
|
|||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user