From 7bf02ff2ccffd168d507b162524ce5e6437fa4df Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 4 Aug 2023 22:57:03 -0700 Subject: [PATCH] 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. --- src/cmp.c | 2 +- src/diff.c | 2 +- src/dir.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmp.c b/src/cmp.c index f07a5d5..99fc0bb 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -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) { diff --git a/src/diff.c b/src/diff.c index 4e7fd1e..4312f59 100644 --- a/src/diff.c +++ b/src/diff.c @@ -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 diff --git a/src/dir.c b/src/dir.c index cd099d8..126f512 100644 --- a/src/dir.c +++ b/src/dir.c @@ -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;