This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
[glibc/zack/no-nested-includes] Don’t include signal.h from sys/param.h.
- From: Zack Weinberg <zack at sourceware dot org>
- To: glibc-cvs at sourceware dot org
- Date: 18 Jun 2019 15:37:10 -0000
- Subject: [glibc/zack/no-nested-includes] Don’t include signal.h from sys/param.h.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a8394a5777c3a078565681c23015aae09feea80a
commit a8394a5777c3a078565681c23015aae09feea80a
Author: Zack Weinberg <zackw@panix.com>
Date: Mon Jun 10 12:34:36 2019 -0400
Donâ??t include signal.h from sys/param.h.
sys/param.h is the last public header that includes signal.h. It is
not clear what subset of the definitions from signal.h are actually
expected by historical users of sys/param.h; Iâ??ve chosen to take the
comment at face value and cut it down to bits/signum.h, which supplies
_NSIG and all of the SIG* constants. This requires adjusting every copy
of bits/signum.h to permit inclusion by sys/param.h as well as signal.h.
While I was at it I moved the comment about sys/param.h being obsolete
from sysdeps/mach/hurd/bits/param.h, where itâ??s not likely to be seen,
to the top-level sys/param.h, and edited it to give more useful advice.
bits/procfs.h ceased to include signal.h as of several patches ago but
I didnâ??t realize Iâ??d done that until now.
* misc/sys/param.h: Include bits/signum.h, not signal.h.
Add comment explaining that this header is obsolete, based on
a similar comment in Hurd bits/param.h.
* bits/param.h: Add multiple inclusion guard and defensive #error.
* sysdeps/mach/hurd/bits/param.h: Add multiple inclusion guard.
Remove comment explaining that this header is obsolete (see above).
* sysdeps/mach/i386/bits/mach/param.h: Add multiple inclusion guard.
* sysdeps/unix/sysv/linux/bits/param.h: Add multiple inclusion guard.
* bits/signum-generic.h, bits/signum.h
* sysdeps/unix/bsd/bits/signum.h
* sysdeps/unix/sysv/linux/alpha/bits/signum.h
* sysdeps/unix/sysv/linux/bits/signum.h
* sysdeps/unix/sysv/linux/hppa/bits/signum.h
* sysdeps/unix/sysv/linux/mips/bits/signum.h:
Allow inclusion by sys/param.h as well as signal.h.
* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
Update.
Diff:
---
bits/param.h | 7 +++++++
bits/signum-generic.h | 2 +-
bits/signum.h | 2 +-
misc/sys/param.h | 8 +++++++-
scripts/check-obsolete-constructs.py | 5 ++---
sysdeps/mach/hurd/bits/param.h | 13 ++++++-------
sysdeps/mach/i386/bits/mach/param.h | 5 +++++
sysdeps/unix/bsd/bits/signum.h | 2 +-
sysdeps/unix/sysv/linux/alpha/bits/signum.h | 2 +-
sysdeps/unix/sysv/linux/bits/param.h | 5 +++++
sysdeps/unix/sysv/linux/bits/signum.h | 2 +-
sysdeps/unix/sysv/linux/hppa/bits/signum.h | 2 +-
sysdeps/unix/sysv/linux/mips/bits/signum.h | 2 +-
sysdeps/unix/sysv/linux/sparc/bits/signum.h | 2 +-
14 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/bits/param.h b/bits/param.h
index e83f60f..44c8505 100644
--- a/bits/param.h
+++ b/bits/param.h
@@ -16,6 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
#ifndef _SYS_PARAM_H
# error "Never use <bits/param.h> directly; include <sys/param.h> instead."
#endif
@@ -31,3 +34,7 @@
EXEC_PAGESIZE
*/
+
+#error "Generic bits/param.h should not have been used."
+
+#endif
diff --git a/bits/signum-generic.h b/bits/signum-generic.h
index 6fbbf20..71308d6 100644
--- a/bits/signum-generic.h
+++ b/bits/signum-generic.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_GENERIC_H
#define _BITS_SIGNUM_GENERIC_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum-generic.h> directly; use <signal.h> instead."
#endif
diff --git a/bits/signum.h b/bits/signum.h
index 8c788c8..90e13c9 100644
--- a/bits/signum.h
+++ b/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/misc/sys/param.h b/misc/sys/param.h
index bb6478f..1dedc69 100644
--- a/misc/sys/param.h
+++ b/misc/sys/param.h
@@ -16,6 +16,12 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+/* This header is provided only for compatibility with historic Unix
+ systems. New programs should use some combination of <endian.h>,
+ <limits.h>, <signal.h>, <stddef.h>, <stdint.h>, and <sys/types.h>
+ instead, and the names defined in those headers. The utility
+ macros at the end of this header should not be used at all. */
+
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H 1
@@ -24,7 +30,7 @@
#include <sys/types.h>
#include <limits.h>
#include <endian.h> /* Define BYTE_ORDER et al. */
-#include <signal.h> /* Define NSIG. */
+#include <bits/signum.h> /* Define NSIG. */
#include <bits/NULL.h>
/* This file defines some things in system-specific ways. */
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 6c916fb..3765c57 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -573,8 +573,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/ioctl.h": [ "sys/ttydefaults.h" ],
"sys/mount.h": [ "sys/ioctl.h" ],
"sys/mtio.h": [ "sys/ioctl.h" ],
- "sys/param.h": [ "endian.h", "limits.h", "signal.h",
- "sys/types.h" ],
+ "sys/param.h": [ "endian.h", "limits.h", "sys/types.h" ],
"sys/procfs.h": [ "sys/ucontext.h", "sys/user.h" ],
"sys/ptrace.h": [ "sys/ucontext.h" ],
"sys/raw.h": [ "sys/ioctl.h" ],
@@ -624,7 +623,7 @@ HEADER_ALLOWED_INCLUDES = {
"features.h": [ "gnu/stubs.h", "stdc-predef.h",
"sys/cdefs.h" ],
- "bits/procfs.h": [ "signal.h", "sys/ucontext.h" ],
+ "bits/procfs.h": [ "sys/ucontext.h" ],
"bits/types/__va_list.h": [ "stdarg.h" ],
"bits/types/ptrdiff_t.h": [ "stddef.h" ],
diff --git a/sysdeps/mach/hurd/bits/param.h b/sysdeps/mach/hurd/bits/param.h
index a0162e9..09485f1 100644
--- a/sysdeps/mach/hurd/bits/param.h
+++ b/sysdeps/mach/hurd/bits/param.h
@@ -16,19 +16,16 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
#ifndef _SYS_PARAM_H
# error "Never use <bits/param.h> directly; include <sys/param.h> instead."
#endif
#include <bits/mach/param.h>
-/* This file is deprecated and is provided only for compatibility with
- Unix systems. It is unwise to include this file on programs which
- are intended only for GNU systems.
-
- Parts from:
-
- * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
+/* Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -85,3 +82,5 @@
#define FSHIFT 11 /* Bits to right of fixed binary point. */
#define FSCALE (1<<FSHIFT)
+
+#endif /* bits/param.h */
diff --git a/sysdeps/mach/i386/bits/mach/param.h b/sysdeps/mach/i386/bits/mach/param.h
index 09a549d..3fbe86a 100644
--- a/sysdeps/mach/i386/bits/mach/param.h
+++ b/sysdeps/mach/i386/bits/mach/param.h
@@ -16,6 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _BITS_MACH_PARAM_H
+#define _BITS_MACH_PARAM_H 1
+
#ifndef _SYS_PARAM_H
# error "Never use <bits/mach/param.h> directly; include <sys/param.h> instead."
#endif
@@ -23,3 +26,5 @@
#ifndef EXEC_PAGESIZE
#define EXEC_PAGESIZE 4096
#endif
+
+#endif
diff --git a/sysdeps/unix/bsd/bits/signum.h b/sysdeps/unix/bsd/bits/signum.h
index 7e3df32..e0178e9 100644
--- a/sysdeps/unix/bsd/bits/signum.h
+++ b/sysdeps/unix/bsd/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/signum.h b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
index da4ff93..4355d35 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/sysdeps/unix/sysv/linux/bits/param.h b/sysdeps/unix/sysv/linux/bits/param.h
index 53c0f9f..f847c51 100644
--- a/sysdeps/unix/sysv/linux/bits/param.h
+++ b/sysdeps/unix/sysv/linux/bits/param.h
@@ -16,6 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
#ifndef _SYS_PARAM_H
# error "Never use <bits/param.h> directly; include <sys/param.h> instead."
#endif
@@ -40,3 +43,5 @@
and NCARGS anyway. */
#define NOFILE 256
#define NCARGS 131072
+
+#endif /* bits/param.h */
diff --git a/sysdeps/unix/sysv/linux/bits/signum.h b/sysdeps/unix/sysv/linux/bits/signum.h
index 25b0d2a..86fde6a 100644
--- a/sysdeps/unix/sysv/linux/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/signum.h b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
index c643626..5959966 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/sysdeps/unix/sysv/linux/mips/bits/signum.h b/sysdeps/unix/sysv/linux/mips/bits/signum.h
index 89a63e4..1a430c1 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/signum.h b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
index ec746fe..866a1c3 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
@@ -19,7 +19,7 @@
#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif