History

keys: Fix the use of the C++ keyword "private" in uapi/linux/keyctl.h

The keyctl_dh_params struct in uapi/linux/keyctl.h contains the symbol "private" which means that the header file will cause compilation failure if #included in to a C++ program. Further, the patch that added the same struct to the keyutils package named the symbol "priv", not "private". The previous attempt to fix this (commit 8a2336e549d3) did so by simply renaming the kernel's copy of the field to dh_private, but this then breaks existing userspace and as such has been reverted (commit 8c0f9f5b309d). [And note, to those who think that wrapping the struct in extern "C" {} will work: it won't; that only changes how symbol names are presented to the assembler and linker.]. Instead, insert an anonymous union around the "private" member and add a second member in there with the name "priv" to match the one in the keyutils package. The "private" member is then wrapped in !__cplusplus cpp-conditionals to hide it from C++.

David Howells committed 8 years ago

Commit 2ecefa01 parent 0d42d731 file · +6 −1Browse files

Showing the changes to include/uapi/linux (1 of 1 file). Show all

Unified · Split

include/uapi/linux/keyctl.h+6−1
@@ -65,7 +65,12 @@ · 64 unmodified lines
6565
6666 /* keyctl structures */
6767 struct keyctl_dh_params {
68− __s32 private;
68+ union {
69+#ifndef __cplusplus
70+ __s32 private;
71+#endif
72+ __s32 priv;
73+ };
6974 __s32 prime;
7075 __s32 base;
7176 };