about summary refs log tree commit diff
path: root/signal/bits
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2017-08-16 20:33:59 +0000
committerJoseph Myers <joseph@codesourcery.com>2017-08-16 20:33:59 +0000
commit67f0aff0c63e5deaade7f6cc7758f5cb63344fb8 (patch)
tree6cd8f38178b1ba6c4c73bf2f61d4e24df1e975dc /signal/bits
parent87e7bf4d36af0a4622dc2687730f26d7d53003fe (diff)
downloadglibc-67f0aff0c63e5deaade7f6cc7758f5cb63344fb8.tar.gz
glibc-67f0aff0c63e5deaade7f6cc7758f5cb63344fb8.tar.xz
glibc-67f0aff0c63e5deaade7f6cc7758f5cb63344fb8.zip
Fix sigval namespace (bug 21944).
XPG4.2 defines the siginfo_t type, but not union sigval or its
contents (which were added in the 1993 edition of POSIX.1), resulting
in namespace violations for sigval, sival_int and sival_ptr for
signal.h and sys/wait.h for that standard because those headers
incorrectly expose those names in that case.

This patch fixes this problem.  The public type in this case is union
sigval, but various places in the headers use the sigval_t name for
it; direct uses of union sigval are already properly guarded or in
headers not in XPG4.2.  Now, sigval_t, although not a standard name,
does seem to be widely used outside glibc.  The approach taken by this
patch is to make installed headers use the name __sigval_t instead.
__sigval_t is then defined to either union sigval or union __sigval
(where union __sigval has __-prefixed member names as well), depending
on whether there are any namespace issues with the union sigval name
and its members.  In the case where union __sigval is used, sigval_t
is not defined at all, to avoid the problem of sigval_t having a C++
mangled name that depends on feature test macros.  sigval_t is still
defined by signal.h if __USE_MISC (reflecting the nonstandard nature
of that name).

Tested for x86_64.

	[BZ #21944]
	* signal/bits/types/__sigval_t.h: New file.
	* signal/Makefile (headers): Add bits/types/__sigval_t.h.
	* signal/bits/types/sigval_t.h: Include <bits/types/__sigval_t.h>
	and define sigval_t using __sigval_t.
	* include/bits/types/__sigval_t.h: New file.
	* bits/types/sigevent_t.h: Include <bits/types/__sigval_t.h>
	instead of <bits/types/__sigval_t.h>.
	(struct sigevent): Use __sigval_t instead of sigval_t.
	* bits/types/siginfo_t.h: Include <bits/types/__sigval_t.h>
	instead of <bits/types/__sigval_t.h>.
	(siginfo_t): Use __sigval_t instead of sigval_t.
	* sysdeps/unix/sysv/linux/bits/types/sigevent_t.h: Include
	<bits/types/__sigval_t.h> instead of <bits/types/__sigval_t.h>.
	(struct sigevent): Use __sigval_t instead of sigval_t.
	* sysdeps/unix/sysv/linux/bits/types/siginfo_t.h: Include
	<bits/types/__sigval_t.h> instead of <bits/types/__sigval_t.h>.
	(siginfo_t): Use __sigval_t instead of sigval_t.
	* signal/signal.h [__USE_MISC]: Include <bits/types/sigval_t.h>.
Diffstat (limited to 'signal/bits')
-rw-r--r--signal/bits/types/__sigval_t.h41
-rw-r--r--signal/bits/types/sigval_t.h21
2 files changed, 54 insertions, 8 deletions
diff --git a/signal/bits/types/__sigval_t.h b/signal/bits/types/__sigval_t.h
new file mode 100644
index 0000000000..79b4ffe401
--- /dev/null
+++ b/signal/bits/types/__sigval_t.h
@@ -0,0 +1,41 @@
+/* Define __sigval_t.
+   Copyright (C) 1997-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef ____sigval_t_defined
+#define ____sigval_t_defined
+
+/* Type for data associated with a signal.  */
+#ifdef __USE_POSIX199309
+union sigval
+{
+  int sival_int;
+  void *sival_ptr;
+};
+
+typedef union sigval __sigval_t;
+#else
+union __sigval
+{
+  int __sival_int;
+  void *__sival_ptr;
+};
+
+typedef union __sigval __sigval_t;
+#endif
+
+#endif
diff --git a/signal/bits/types/sigval_t.h b/signal/bits/types/sigval_t.h
index 666598f0ca..a05d7f469f 100644
--- a/signal/bits/types/sigval_t.h
+++ b/signal/bits/types/sigval_t.h
@@ -1,13 +1,18 @@
 #ifndef __sigval_t_defined
 #define __sigval_t_defined
 
-/* Type for data associated with a signal.  */
-union sigval
-{
-  int sival_int;
-  void *sival_ptr;
-};
-
-typedef union sigval sigval_t;
+#include <bits/types/__sigval_t.h>
+
+/* To avoid sigval_t (not a standard type name) having C++ name
+   mangling depending on whether the selected standard includes union
+   sigval, it should not be defined at all when using a standard for
+   which the sigval name is not reserved; in that case, headers should
+   not include <bits/types/sigval_t.h> and should use only the
+   internal __sigval_t name.  */
+#ifndef __USE_POSIX199309
+# error "sigval_t defined for standard not including union sigval"
+#endif
+
+typedef __sigval_t sigval_t;
 
 #endif