* cfg.mk (sc_require_fcntl_safer): New syntax-check.
* gl/modules/targetdir (Depends-on): Depend on fcntl-safer instead of
fcntl-h.
* gl/modules/fd-reopen (Depends-on): Likewise. Add a missing
unistd-safer dependency.
* gl/lib/targetdir.c: Include fcntl--.h instead of fcntl.h.
* gl/lib/fd-reopen.c: Include fcntl--.h.
* src/cat.c: Likewise.
* src/chmod.c: Likewise.
* src/chown-core.c: Likewise.
* src/df.c: Likewise.
* src/head.c: Likewise.
* src/install.c: Likewise.
* src/nohup.c: Likewise.
* src/pinky.c: Likewise.
* src/selinux.c: Likewise.
* src/sort.c: Likewise.
* src/tac.c: Likewise.
* src/wc.c: Likewise.
* src/who.c: Likewise.
* src/system.h: Provide a commented at include for a safe function call.
---
cfg.mk | 14 ++++++++++++++
gl/lib/fd-reopen.c | 2 +-
gl/lib/targetdir.c | 2 +-
gl/modules/fd-reopen | 3 ++-
gl/modules/targetdir | 2 +-
src/cat.c | 1 +
src/chmod.c | 1 +
src/chown-core.c | 1 +
src/df.c | 1 +
src/head.c | 1 +
src/install.c | 1 +
src/nohup.c | 1 +
src/pinky.c | 1 +
src/selinux.c | 1 +
src/sort.c | 1 +
src/system.h | 7 +++++++
src/tac.c | 1 +
src/wc.c | 1 +
src/who.c | 1 +
19 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 80e0fdce3..1736cb666 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -588,6 +588,20 @@ sc_prohibit_short_facl_mode_spec:
halt='setfacl mode string length < 3; extend with hyphen(s)' \
$(_sc_search_regexp)
+# Ensure that "fcntl--.h" is used where appropriate.
+sc_require_fcntl_safer:
+ @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
+ files=$$(grep -El \
+ '(^|[^[:alnum:]_])$(begword)(open(at)?|creat) ?\(' \
+ $$($(VC_LIST_EXCEPT) \
+ | grep '\.[ch]$$')); \
+ test -n "$$files" && grep -LE 'include "fcntl--.h"' $$files \
+ | grep . && \
+ { echo '$(ME): the above files should use "fcntl--.h"' \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+
# Require "stdio--.h" for the fopen-safer and freopen-safer modules.
sc_require_stdio_safer:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
diff --git a/gl/lib/fd-reopen.c b/gl/lib/fd-reopen.c
index 607235feb..dfbe59037 100644
--- a/gl/lib/fd-reopen.c
+++ b/gl/lib/fd-reopen.c
@@ -22,7 +22,7 @@
#include "fd-reopen.h"
#include <errno.h>
-#include <fcntl.h>
+#include "fcntl--.h"
#include "unistd--.h"
/* Open a file to a particular file descriptor. This is like standard
diff --git a/gl/lib/targetdir.c b/gl/lib/targetdir.c
index 24cff48c3..e5ea4dc2e 100644
--- a/gl/lib/targetdir.c
+++ b/gl/lib/targetdir.c
@@ -23,9 +23,9 @@
#include <attribute.h>
#include <errno.h>
-#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
+#include "fcntl--.h"
#ifdef O_PATH
enum { O_PATHSEARCH = O_PATH };
diff --git a/gl/modules/fd-reopen b/gl/modules/fd-reopen
index 70a21c317..935c6c7a5 100644
--- a/gl/modules/fd-reopen
+++ b/gl/modules/fd-reopen
@@ -6,7 +6,8 @@ lib/fd-reopen.c
lib/fd-reopen.h
Depends-on:
-fcntl-h
+fcntl-safer
+unistd-safer
configure.ac:
diff --git a/gl/modules/targetdir b/gl/modules/targetdir
index 1a6f097a8..5f4070007 100644
--- a/gl/modules/targetdir
+++ b/gl/modules/targetdir
@@ -8,7 +8,7 @@ lib/targetdir.h
Depends-on:
attribute
bool
-fcntl-h
+fcntl-safer
configure.ac:
diff --git a/src/cat.c b/src/cat.c
index af48c85c8..97730b91f 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -37,6 +37,7 @@
#include "assure.h"
#include "ioblksize.h"
#include "fadvise.h"
+#include "fcntl--.h"
#include "full-write.h"
#include "isapipe.h"
#include "splice.h"
diff --git a/src/chmod.c b/src/chmod.c
index 835db7dbe..eede81622 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -25,6 +25,7 @@
#include "assure.h"
#include "dev-ino.h"
#include "filemode.h"
+#include "fcntl--.h"
#include "fts-missing.h"
#include "ignore-value.h"
#include "issymlinkat.h"
diff --git a/src/chown-core.c b/src/chown-core.c
index 4698e27eb..70022cab6 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -25,6 +25,7 @@
#include "system.h"
#include "assure.h"
#include "chown-core.h"
+#include "fcntl--.h"
#include "fts-missing.h"
#include "ignore-value.h"
#include "root-dev-ino.h"
diff --git a/src/df.c b/src/df.c
index 005aa3fe1..af53605fa 100644
--- a/src/df.c
+++ b/src/df.c
@@ -27,6 +27,7 @@
#include "system.h"
#include "assure.h"
#include "canonicalize.h"
+#include "fcntl--.h"
#include "fsusage.h"
#include "human.h"
#include "mbswidth.h"
diff --git a/src/head.c b/src/head.c
index 2ce8e4ffa..2ae66a440 100644
--- a/src/head.c
+++ b/src/head.c
@@ -33,6 +33,7 @@
#include "assure.h"
#include "c-ctype.h"
+#include "fcntl--.h"
#include "full-read.h"
#include "stat-size.h"
#include "xbinary-io.h"
diff --git a/src/install.c b/src/install.c
index 5883da583..0f58e91e6 100644
--- a/src/install.c
+++ b/src/install.c
@@ -31,6 +31,7 @@
#include "backupfile.h"
#include "cp-hash.h"
#include "copy.h"
+#include "fcntl--.h"
#include "filenamecat.h"
#include "full-read.h"
#include "mkancesdirs.h"
diff --git a/src/nohup.c b/src/nohup.c
index cfdeaa133..b4295b6a1 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -23,6 +23,7 @@
#include "system.h"
+#include "fcntl--.h"
#include "filenamecat.h"
#include "fd-reopen.h"
#include "long-options.h"
diff --git a/src/pinky.c b/src/pinky.c
index 8c87e6008..dd1f66651 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -25,6 +25,7 @@
#include "canon-host.h"
#include "fadvise.h"
+#include "fcntl--.h"
#include "filenamecat.h"
#include "full-write.h"
#include "hard-locale.h"
diff --git a/src/selinux.c b/src/selinux.c
index d56a7a246..803d5eb3d 100644
--- a/src/selinux.c
+++ b/src/selinux.c
@@ -23,6 +23,7 @@
#include "system.h"
#include "canonicalize.h"
+#include "fcntl--.h"
#include "xfts.h"
#include "selinux.h"
diff --git a/src/sort.c b/src/sort.c
index 74f712b94..398ca149d 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -34,6 +34,7 @@
#include "assure.h"
#include "c-ctype.h"
#include "fadvise.h"
+#include "fcntl--.h"
#include "filevercmp.h"
#include "findprog.h"
#include "flexmember.h"
diff --git a/src/system.h b/src/system.h
index 30636118d..e16bee0d6 100644
--- a/src/system.h
+++ b/src/system.h
@@ -313,6 +313,13 @@ enum {
DS_EMPTY = -1,
DS_NONEMPTY = 0,
};
+
+/* This header only calls open(at)? here and closes the file descriptor before
+ returning, without using standard input, output, or error. Comment out
+ this include to make sc_require_fcntl_safer happy. */
+
+/* #include "fcntl--.h" */
+
static inline int
directory_status (int fd_cwd, char const *dir)
{
diff --git a/src/tac.c b/src/tac.c
index dcfa30824..0b2c37a0d 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -43,6 +43,7 @@ tac -r -s '.\|
#include <regex.h>
+#include "fcntl--.h"
#include "filenamecat.h"
#include "full-read.h"
#include "full-write.h"
diff --git a/src/wc.c b/src/wc.c
index 569fe067d..2d0db2924 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -38,6 +38,7 @@
#include "system.h"
#include "assure.h"
#include "cpu-supports.h"
+#include "fcntl--.h"
#include "ioblksize.h"
#include "stdio--.h"
#include "wc.h"
diff --git a/src/who.c b/src/who.c
index 5b35b8bd7..cccec3f0f 100644
--- a/src/who.c
+++ b/src/who.c
@@ -32,6 +32,7 @@
#include "c-ctype.h"
#include "canon-host.h"
+#include "fcntl--.h"
#include "readutmp.h"
#include "hard-locale.h"
#include "quote.h"
--
2.56.1