]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
commonio_open: Remove fcntl call
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 5 May 2023 11:59:07 +0000 (11:59 +0000)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 5 May 2023 14:15:46 +0000 (16:15 +0200)
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>
lib/commonio.c

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