[icinga-checkins] icinga.org: icinga-core/dev/ido: fix build issues on modules and broken snprintf function causing segv on solaris #1772

git at icinga.org git at icinga.org
Mon Feb 6 15:54:48 CET 2012


Module: icinga-core
Branch: dev/ido
Commit: 06a7deee64a2c5d9c53b64c1eac2e86a6f439dbb
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=06a7deee64a2c5d9c53b64c1eac2e86a6f439dbb

Author: Thomas Dressler <tdressler at tdressler.net>
Date:   Sun Jan 29 17:17:35 2012 +0100

fix build issues on modules and broken snprintf function causing segv on solaris #1772
refs #1772, #1253

---

 common/snprintf.c               |   13 +++++++++++++
 configure                       |   23 ++++++++++++++++++-----
 configure.in                    |   21 ++++++++++++++++-----
 include/config.h.in             |    2 ++
 include/snprintf.h.in           |    1 +
 module/Makefile.in              |    5 +++--
 module/idoutils/src/Makefile.in |   13 +++++++++----
 7 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/common/snprintf.c b/common/snprintf.c
index ac84745..4cfec6a 100644
--- a/common/snprintf.c
+++ b/common/snprintf.c
@@ -122,6 +122,19 @@
 #  include <math.h>
 #endif /* TEST_SNPRINTF */
 
+#ifdef SNPRINTF_BROKEN
+/* snprintf and friends are known broken at least in solaris
+ * we assume functions are not there to take local one
+ */
+#undef HAVE_SNPRINTF
+#undef HAVE_VSNPRINTF
+#undef HAVE_C99_VSNPRINTF
+#undef HAVE_ASPRINTF
+#undef HAVE_VASPRINTF
+#undef HAVE_VA_COPY 
+#endif
+
+
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
diff --git a/configure b/configure
index 3e40ea8..be18168 100755
--- a/configure
+++ b/configure
@@ -5645,7 +5645,7 @@ $as_echo "$ac_cv_func_vsnprintf" >&6; }
 if test "x$ac_cv_func_vsnprintf" = x""yes; then
   :
 else
-  SNPRINTF_O_IDO=../../../common/snprintf.o
+  SNPRINTF_O_IDO=snprintf.o
 fi
 
 { $as_echo "$as_me:$LINENO: checking for snprintf" >&5
@@ -5736,7 +5736,7 @@ $as_echo "$ac_cv_func_snprintf" >&6; }
 if test "x$ac_cv_func_snprintf" = x""yes; then
   :
 else
-  SNPRINTF_O_IDO=../../../common/snprintf.o
+  SNPRINTF_O_IDO=snprintf.o
 fi
 
 { $as_echo "$as_me:$LINENO: checking for asprintf" >&5
@@ -5827,7 +5827,7 @@ $as_echo "$ac_cv_func_asprintf" >&6; }
 if test "x$ac_cv_func_asprintf" = x""yes; then
   :
 else
-  SNPRINTF_O_IDO=../../../common/snprintf.o
+  SNPRINTF_O_IDO=snprintf.o
 fi
 
 { $as_echo "$as_me:$LINENO: checking for vasprintf" >&5
@@ -5918,7 +5918,7 @@ $as_echo "$ac_cv_func_vasprintf" >&6; }
 if test "x$ac_cv_func_vasprintf" = x""yes; then
   :
 else
-  SNPRINTF_O_IDO=../../../common/snprintf.o
+  SNPRINTF_O_IDO=snprintf.o
 fi
 
 
@@ -8757,8 +8757,10 @@ $as_echo "$BROKER_LDFLAGS" >&6; }
 $as_echo_n "checking for linker flags for loadable modules... " >&6; }
 	case $host_os in
 		solaris2*|sysv4*)
-			MOD_LDFLAGS="-G"
+			MOD_LDFLAGS="-G -fPIC"
+			MOD_CFLAGS="-fPIC"
 			INIT_OPTS="-o root -g root"
+			SNPRINTF_BROKEN="yes"
 		;;
 		aix4*|aix5*)
 			#MOD_LDFLAGS="-G -bnoentry -bexpall"
@@ -8811,6 +8813,17 @@ _ACEOF
 
 fi
 
+if test x$SNPRINTF_BROKEN = xyes; then
+	cat >>confdefs.h <<\_ACEOF
+#define SNPRINTF_BROKEN "1"
+_ACEOF
+
+	SNPRINTF_O=../common/snprintf.o
+	SNPRINTF_O_IDO=snprintf.o
+
+
+fi
+
 USE_STATE_BASED_ESCAL_RANGES=no
 # Check whether --enable-state-based-escal-ranges was given.
 if test "${enable_state_based_escal_ranges+set}" = set; then
diff --git a/configure.in b/configure.in
index 65512f0..bf0be3c 100644
--- a/configure.in
+++ b/configure.in
@@ -68,10 +68,10 @@ AC_CHECK_FUNC(asprintf,,SNPRINTF_O=../common/snprintf.o)
 AC_CHECK_FUNC(vasprintf,,SNPRINTF_O=../common/snprintf.o)
 
 dnl module/idoutils/src/Makefile.in
-AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O_IDO=../../../common/snprintf.o)
-AC_CHECK_FUNC(snprintf,,SNPRINTF_O_IDO=../../../common/snprintf.o)
-AC_CHECK_FUNC(asprintf,,SNPRINTF_O_IDO=../../../common/snprintf.o)
-AC_CHECK_FUNC(vasprintf,,SNPRINTF_O_IDO=../../../common/snprintf.o)
+AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O_IDO=snprintf.o)
+AC_CHECK_FUNC(snprintf,,SNPRINTF_O_IDO=snprintf.o)
+AC_CHECK_FUNC(asprintf,,SNPRINTF_O_IDO=snprintf.o)
+AC_CHECK_FUNC(vasprintf,,SNPRINTF_O_IDO=snprintf.o)
 
 AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[
 AC_TRY_RUN([
@@ -717,8 +717,10 @@ if test x$USE_EVENTBROKER = xyes; then
 	AC_MSG_CHECKING(for linker flags for loadable modules)
 	case $host_os in
 		solaris2*|sysv4*)
-			MOD_LDFLAGS="-G"
+			MOD_LDFLAGS="-G -fPIC"
+			MOD_CFLAGS="-fPIC"
 			INIT_OPTS="-o root -g root"
+			SNPRINTF_BROKEN="yes"
 		;;
 		aix4*|aix5*)
 			#MOD_LDFLAGS="-G -bnoentry -bexpall"
@@ -766,6 +768,15 @@ if test x$USE_EVENTBROKER = xyes; then
 	AC_SUBST(BROKER_H)
 fi
 
+dnl workaround for broken printf implementations (like solaris)
+if test x$SNPRINTF_BROKEN = xyes; then
+	AC_DEFINE(SNPRINTF_BROKEN,"1")
+	SNPRINTF_O=../common/snprintf.o
+	SNPRINTF_O_IDO=snprintf.o
+	AC_SUBST(SNPRINTF_O)
+	AC_SUBST(SNPRINTF_O_IDO)
+fi
+
 dnl Configure state based escalation ranges
 USE_STATE_BASED_ESCAL_RANGES=no
 AC_ARG_ENABLE(state-based-escal-ranges,AC_HELP_STRING([--enable-state-based-escal-ranges],[enables state based escalation ranges - attention: interferes with mk_livestatus neb module]),USE_STATE_BASED_ESCAL_RANGES=$enableval,USE_STATE_BASED_ESCAL_RANGES=no)
diff --git a/include/config.h.in b/include/config.h.in
index 3929b7b..87dbd54 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -386,4 +386,6 @@
 #define ENV_PREFIX	"ICINGA_"
 #endif
 
+/*snprintf workaround*/
+#undef SNPRINTF_BROKEN
 #endif
diff --git a/include/snprintf.h.in b/include/snprintf.h.in
index c4a1446..8ab5880 100644
--- a/include/snprintf.h.in
+++ b/include/snprintf.h.in
@@ -1,3 +1,4 @@
 /* -*- C -*- */
 #undef HAVE_SNPRINTF
 #undef NEED_VA_LIST
+#undef SNPRINTF_BROKEN
diff --git a/module/Makefile.in b/module/Makefile.in
index 6de9eb8..ee81c84 100644
--- a/module/Makefile.in
+++ b/module/Makefile.in
@@ -26,11 +26,12 @@ CP=@CP@
 all:	helloworld.o
 
 helloworld.o: helloworld.c
-	$(CC) $(MOD_CFLAGS) $(CFLAGS) -o helloworld.o helloworld.c $(MOD_LDFLAGS) $(LDFLAGS) $(LIBS)
+	$(CC) $(MOD_CFLAGS) $(CFLAGS) -o helloworld.so helloworld.c $(MOD_LDFLAGS) $(LDFLAGS) $(LIBS)
+	mv helloworld.so helloworld.o
 
 clean:
 	rm -f helloworld.o
-	rm -f core *.o
+	rm -f core *.o *.so
 	rm -f *~ *.*~
 
 distclean: clean
diff --git a/module/idoutils/src/Makefile.in b/module/idoutils/src/Makefile.in
index 4673dda..3bdbafa 100644
--- a/module/idoutils/src/Makefile.in
+++ b/module/idoutils/src/Makefile.in
@@ -41,6 +41,7 @@ THREADLIBS=@THREADLIBS@
 
 # asprintf for Solaris friends ;) 
 SNPRINTF_O_IDO=@SNPRINTF_O_IDO@
+SNPRINTF_C=../../../common/snprintf.c
 
 
 COMMON_INC=$(CORE_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/io.h $(SRC_INCLUDE)/protoapi.h $(SRC_INCLUDE)/utils.h $(SRC_INCLUDE)/sla.h $(SRC_INCLUDE)/logging.h
@@ -68,16 +69,17 @@ ido2db: ido2db.c $(IDO_INC) $(IDO_OBJS) $(COMMON_INC) $(COMMON_OBJS) $(IDO2DB_OB
 	$(CC) $(CFLAGS) $(DBCFLAGS) -o ido2db ido2db.c $(IDO2DB_OBJS) $(COMMON_OBJS) $(IDO_OBJS) $(LDFLAGS) $(DBLDFLAGS) $(LIBS) $(SOCKETLIBS) $(DBLIBS) $(THREADLIBS) $(MATHLIBS) $(OTHERLIBS)
 
 idomod.o: idomod.c $(COMMON_INC) $(COMMON_OBJS)
-	$(CC) $(MOD_CFLAGS) $(CFLAGS) -o idomod.o idomod.c $(COMMON_OBJS) $(MOD_LDFLAGS) $(LDFLAGS) $(LIBS) $(SOCKETLIBS) $(OTHERLIBS)
+	$(CC) $(MOD_CFLAGS) $(CFLAGS) -o idomod.so idomod.c $(COMMON_OBJS) $(MOD_LDFLAGS) $(LDFLAGS) $(LIBS) $(SOCKETLIBS) $(OTHERLIBS)
+	mv idomod.so idomod.o
 
 sockdebug: sockdebug.c $(COMMON_INC) $(COMMON_OBJS)
 	$(CC) $(CFLAGS) -o $@ sockdebug.c $(COMMON_OBJS) $(LDFLAGS) $(LIBS) $(MATHLIBS) $(SOCKETLIBS) $(OTHERLIBS)
 
 io.o: io.c $(SRC_INCLUDE)/io.h
-	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ io.c
+	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ io.c $(MOD_LDFLAGS)
 
 utils.o: utils.c $(SRC_INCLUDE)/utils.h
-	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ utils.c
+	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ utils.c $(MOD_LDFLAGS)
 
 db.o: db.c $(SRC_INCLUDE)/db.h
 	$(CC) $(CFLAGS) -c -o $@ db.c
@@ -94,8 +96,11 @@ sla.o: sla.c $(COMMON_INC)
 logging.o: logging.c $(COMMON_INC)
 	$(CC) $(CFLAGS) -c -o $@ logging.c
 
+snprintf.o: $(SNPRINTF_C) $(CORE_INCLUDE)/snprintf.h
+	$(CC) $(MOD_CFLAGS) $(CFLAGS) -c -o $@ $(SNPRINTF_C) $(MOD_LDFLAGS)
+
 clean:
-	rm -f core file2sock log2ido ido2db sockdebug *.o
+	rm -f core file2sock log2ido ido2db sockdebug *.o *.so
 	rm -f *~ */*~
 
 distclean: clean





More information about the icinga-checkins mailing list