[SSSD] [PATCH] Only set _GNU_SOURCE if not already set

Sumit Bose sbose at redhat.com
Thu May 19 15:12:33 UTC 2011


Hi,

there are a couple of places where we set _GNU_SOURCE in the source
files to enable glibc specific extensions. If by chance
'-D_GNU_SOURCE=1' is set on the gcc command line, e.g. by using the
CFLAGS from a pkg-config output (yes, there are examples :-), we get
'"_GNU_SOURCE" redefined' message during compilation. With the attached
patch _GNU_SOURCE is only defined in the sources if not already set.

An alternative fix would be to remove all defines of _GNU_SOURCE from
the source code and add AC_USE_SYSTEM_EXTENSIONS/AC_GNU_SOURCE to
configure.ac . I'm not sure if there is a recommended way how to handle
_GNU_SOURCE and friends.

bye,
Sumit
-------------- next part --------------
From cd87293c9ca06d0e7d16f638ec3e30fcc6b6f72e Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 19 May 2011 09:58:09 +0200
Subject: [PATCH] Only set _GNU_SOURCE if not already set

---
 src/confdb/confdb.c                            |    2 ++
 src/external/platform.m4                       |    4 +++-
 src/krb5_plugin/sssd_krb5_locator_plugin.c     |    4 ++++
 src/monitor/monitor.c                          |    3 +++
 src/responder/common/responder_common.c        |    2 ++
 src/sss_client/common.c                        |    2 ++
 src/tools/selinux.c                            |    3 +++
 src/util/crypto/libcrypto/crypto_sha512crypt.c |    3 +++
 src/util/crypto/nss/nss_sha512crypt.c          |    3 +++
 src/util/debug.c                               |    2 ++
 src/util/server.c                              |    3 +++
 11 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c
index 4975a42..b89546e 100644
--- a/src/confdb/confdb.c
+++ b/src/confdb/confdb.c
@@ -19,7 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #include <ctype.h>
 #include "config.h"
diff --git a/src/external/platform.m4 b/src/external/platform.m4
index 051fe07..03729b9 100644
--- a/src/external/platform.m4
+++ b/src/external/platform.m4
@@ -37,7 +37,9 @@ AM_CONDITIONAL([HAVE_DEBIAN], [test x"$osname" = xdebian])
 AM_CONDITIONAL([HAVE_GENTOO], [test x"$osname" = xgentoo])
 
 AC_CHECK_MEMBERS([struct ucred.pid, struct ucred.uid, struct ucred.gid], , ,
-                 [[#define _GNU_SOURCE
+                 [[#ifndef _GNU_SOURCE
+                   #define _GNU_SOURCE
+                   #endif
                    #include <sys/socket.h>]])
 
 if test x"$ac_cv_member_struct_ucred_pid" = xyes -a \
diff --git a/src/krb5_plugin/sssd_krb5_locator_plugin.c b/src/krb5_plugin/sssd_krb5_locator_plugin.c
index a4dc31c..dbf8bc3 100644
--- a/src/krb5_plugin/sssd_krb5_locator_plugin.c
+++ b/src/krb5_plugin/sssd_krb5_locator_plugin.c
@@ -17,7 +17,11 @@
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
+
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 59ffeb3..c9693c8 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -19,7 +19,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/time.h>
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
index 37761ae..1824b4f 100644
--- a/src/responder/common/responder_common.c
+++ b/src/responder/common/responder_common.c
@@ -20,7 +20,9 @@
 */
 
 /* for struct ucred */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #include <stdio.h>
 #include <unistd.h>
diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index c8a9515..c3f8a9a 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -24,7 +24,9 @@
  */
 
 /* for struct ucred */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #include <nss.h>
 #include <security/pam_modules.h>
diff --git a/src/tools/selinux.c b/src/tools/selinux.c
index 647fc17..4b66f47 100644
--- a/src/tools/selinux.c
+++ b/src/tools/selinux.c
@@ -21,7 +21,10 @@
 
 #include "config.h"
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 
 #ifdef HAVE_SELINUX
diff --git a/src/util/crypto/libcrypto/crypto_sha512crypt.c b/src/util/crypto/libcrypto/crypto_sha512crypt.c
index 29900cc..7971ac9 100644
--- a/src/util/crypto/libcrypto/crypto_sha512crypt.c
+++ b/src/util/crypto/libcrypto/crypto_sha512crypt.c
@@ -10,7 +10,10 @@
 /* SHA512-based Unix crypt implementation.
    Released into the Public Domain by Ulrich Drepper <drepper at redhat.com>.  */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <endian.h>
 #include <errno.h>
 #include <limits.h>
diff --git a/src/util/crypto/nss/nss_sha512crypt.c b/src/util/crypto/nss/nss_sha512crypt.c
index 514e4d9..7a31c6e 100644
--- a/src/util/crypto/nss/nss_sha512crypt.c
+++ b/src/util/crypto/nss/nss_sha512crypt.c
@@ -8,7 +8,10 @@
 /* SHA512-based Unix crypt implementation.
    Released into the Public Domain by Ulrich Drepper <drepper at redhat.com>.  */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <endian.h>
 #include <errno.h>
 #include <limits.h>
diff --git a/src/util/debug.c b/src/util/debug.c
index dbd54c1..93e7c17 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -19,7 +19,9 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
diff --git a/src/util/server.c b/src/util/server.c
index e126237..cff6ebb 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -23,7 +23,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-- 
1.7.5.1



More information about the sssd-devel mailing list