commonio_open: Remove fcntl call

The fcntl call to set FD_CLOEXEC can be performed directly with the
previously performed open call by using the O_CLOEXEC flag.

O_CLOEXEC is required by POSIX.1-2008.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
This commit is contained in:
Samanta Navarro 2023-05-05 11:59:07 +00:00 committed by Iker Pedrosa
parent e899e3d745
commit 627631bf9a

View File

@ -462,7 +462,7 @@ int commonio_open (struct commonio_db *db, int mode)
fd = open (db->filename, fd = open (db->filename,
(db->readonly ? O_RDONLY : O_RDWR) (db->readonly ? O_RDONLY : O_RDWR)
| O_NOCTTY | O_NONBLOCK | O_NOFOLLOW); | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW | O_CLOEXEC);
saved_errno = errno; saved_errno = errno;
db->fp = NULL; db->fp = NULL;
if (fd >= 0) { if (fd >= 0) {
@ -493,9 +493,6 @@ int commonio_open (struct commonio_db *db, int mode)
return 0; return 0;
} }
/* Do not inherit fd in spawned processes (e.g. nscd) */
fcntl (fileno (db->fp), F_SETFD, FD_CLOEXEC);
buflen = BUFLEN; buflen = BUFLEN;
buf = MALLOCARRAY (buflen, char); buf = MALLOCARRAY (buflen, char);
if (NULL == buf) { if (NULL == buf) {