maint: use O_CLOEXEC

* src/cmp.c (main):
* src/diff.c (compare_files):
* src/dir.c (dir_read):
Use O_CLOEXEC when opening files that need not be shared with
child processes.
This commit is contained in:
Paul Eggert 2023-08-04 22:57:03 -07:00
parent b0215c89b8
commit 7bf02ff2cc
3 changed files with 3 additions and 3 deletions

View File

@ -302,7 +302,7 @@ main (int argc, char **argv)
}
else
{
file_desc[f] = open (file[f], O_RDONLY | O_BINARY);
file_desc[f] = open (file[f], O_RDONLY | O_BINARY | O_CLOEXEC);
if (file_desc[f] < 0)
{

View File

@ -1200,7 +1200,7 @@ compare_files (struct comparison const *parent,
= file_name_concat (parent->file[1].name, name1, nullptr);
}
int oflags = ((binary ? O_BINARY : 0)
int oflags = ((binary ? O_BINARY : 0) | O_CLOEXEC
| (no_dereference_symlinks ? O_NOFOLLOW : 0));
/* For both input files X, if X is at the top level and X can be

View File

@ -80,7 +80,7 @@ dir_read (int parentdirfd, struct file_data *dir, struct dirdata *dirdata,
dirfd = openat (parentdirfd,
(parentdirfd < 0 ? dir->name
: last_component (dir->name)),
(O_RDONLY | O_DIRECTORY
(O_RDONLY | O_CLOEXEC | O_DIRECTORY
| (no_dereference_symlinks ? O_NOFOLLOW : 0)));
if (dirfd < 0)
return false;