Browse Source

patches required to build on solaris with asprintf and gettimeofday

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@174 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 23 năm trước cách đây
mục cha
commit
1c4dd10d70
5 tập tin đã thay đổi với 66 bổ sung34 xóa
  1. 5 0
      acconfig.h
  2. 29 25
      configure.in
  3. 16 0
      plugins/common.h.in
  4. 12 4
      plugins/utils.c
  5. 4 5
      plugins/utils.h.in

+ 5 - 0
acconfig.h

@@ -1,15 +1,20 @@
 #undef CGIURL
 #undef CGIURL
 #undef COMPILER_SUPPORTS_LL
 #undef COMPILER_SUPPORTS_LL
 #undef DF_COMMAND
 #undef DF_COMMAND
+#undef HAVE_ASPRINTF
 #undef HAVE_C99_VSNPRINTF
 #undef HAVE_C99_VSNPRINTF
 #undef HAVE_GETOPT_H
 #undef HAVE_GETOPT_H
 #undef HAVE_GETOPT_LONG
 #undef HAVE_GETOPT_LONG
+#undef HAVE_GETTIMEOFDAY
 #undef HAVE_LONGLONG
 #undef HAVE_LONGLONG
 #undef HAVE_PROC_LOADAVG
 #undef HAVE_PROC_LOADAVG
 #undef HAVE_PROC_MEMINFO
 #undef HAVE_PROC_MEMINFO
 #undef HAVE_SSL
 #undef HAVE_SSL
+#undef HAVE_SNPRINTF
 #undef HAVE_SWAP
 #undef HAVE_SWAP
 #undef HAVE_VA_COPY
 #undef HAVE_VA_COPY
+#undef HAVE_VASPRINTF
+#undef HAVE_VSNPRINTF
 #undef NSLOOKUP_COMMAND
 #undef NSLOOKUP_COMMAND
 #undef HOST_COMMAND
 #undef HOST_COMMAND
 #undef PACKAGE_VERSION
 #undef PACKAGE_VERSION

+ 29 - 25
configure.in

@@ -12,17 +12,6 @@ AM_CONFIG_HEADER(plugins/config.h plugins/common.h plugins/version.h plugins/net
 
 
 AC_PREFIX_DEFAULT(/usr/local/nagios)
 AC_PREFIX_DEFAULT(/usr/local/nagios)
 
 
-#AC_DEFUN(AC_HAVE_DECL,
-#[
-# AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
-#    AC_TRY_COMPILE([$2],[int i = (int)$1],
-#        ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
-# if test x"$ac_cv_have_$1_decl" = x"yes"; then
-#    AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
-# fi
-#])
-
-
 dnl Figure out how to invoke "install" and what install options to use.
 dnl Figure out how to invoke "install" and what install options to use.
 
 
 AC_PROG_INSTALL
 AC_PROG_INSTALL
@@ -338,6 +327,28 @@ if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf])
     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf])
 fi
 fi
 
 
+#AC_HAVE_DECL(asprintf, [#include <stdio.h>])
+#AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
+#AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
+#AC_HAVE_DECL(snprintf, [#include <stdio.h>])
+
+AC_CHECK_FUNC(snprintf,
+              AC_DEFINE(HAVE_SNPRINTF,1,[Define if snprintf is present]),
+              LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a")
+AC_CHECK_FUNC(vsnprintf,
+              AC_DEFINE(HAVE_VSNPRINTF,1,[Define if vsnprintf is present]),
+              LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a")
+AC_CHECK_FUNC(vasprintf,
+              AC_DEFINE(HAVE_VASPRINTF,1,[Define if vasprintf is present]),
+              LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a")
+AC_CHECK_FUNC(asprintf,
+              AC_DEFINE(HAVE_ASPRINTF,1,[Define if asprintf is present]),
+              LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a")
+
+if test x"$ac_cv_HAVE_SNPRINTF" = x"no" -o x"$ac_cv_HAVE_VSNPRINTF" = x"no" -o x"$ac_cv_HAVE_VASPRINTF" = x"no" -o x"$ac_cv_HAVE_ASPRINTF" = x"no"; then
+  LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a"
+fi
+
 dnl We used to not do long options unless a compatible lib was found
 dnl We used to not do long options unless a compatible lib was found
 dnl Now we provide code and make libgetopt if native is not suitable
 dnl Now we provide code and make libgetopt if native is not suitable
 AC_MSG_CHECKING(for getopt_long)
 AC_MSG_CHECKING(for getopt_long)
@@ -356,23 +367,16 @@ AC_TRY_COMPILE([#include <getopt.h>
 
 
 AC_CHECK_FUNCS(getopt_long_only,,LIBS="$LIBS -lgetopt" DEPLIBS="$DEPLIBS libgetopt.a")
 AC_CHECK_FUNCS(getopt_long_only,,LIBS="$LIBS -lgetopt" DEPLIBS="$DEPLIBS libgetopt.a")
 
 
-#AC_HAVE_DECL(asprintf, [#include <stdio.h>])
-#AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
-#AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
-#AC_HAVE_DECL(snprintf, [#include <stdio.h>])
-
-AC_CHECK_FUNC(snprintf,AC_DEFINE(HAVE_SNPRINTF,1,[Define if snprintf is present]))
-AC_CHECK_FUNC(vsnprintf,AC_DEFINE(HAVE_VSNPRINTF,1,[Define if vsnprintf is present]))
-AC_CHECK_FUNC(vasprintf,AC_DEFINE(HAVE_VASPRINTF,1,[Define if vasprintf is present]))
-AC_CHECK_FUNC(asprintf,AC_DEFINE(HAVE_ASPRINTF,1,[Define if asprintf is present]))
-
-if test x"$ac_cv_HAVE_SNPRINTF" = x"no" -o x"$ac_cv_HAVE_VSNPRINTF" = x"no" -o x"$ac_cv_HAVE_VASPRINTF" = x"no" -o x"$ac_cv_HAVE_ASPRINTF" = x"no"; then
-  LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a"
-fi
+AC_TRY_COMPILE([#include <sys/time.h>],
+               [struct timeval *foo;],
+               [AC_DEFINE(HAVE_STRUCT_TIMEVAL,1,[Define if we have a timeval structure])])
 
 
+AC_TRY_COMPILE([#include <sys/time.h>],
+               [gettimeofday(NULL, NULL);],
+               AC_DEFINE(HAVE_GETTIMEOFDAY,1,[Define if gettimeofday is found]))
 
 
 dnl Checks for library functions.
 dnl Checks for library functions.
-AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul gettimeofday)
+AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul)
 
 
 AC_MSG_CHECKING(for type of socket size)
 AC_MSG_CHECKING(for type of socket size)
 AC_TRY_COMPILE([#include <stdlib.h>
 AC_TRY_COMPILE([#include <stdlib.h>

+ 16 - 0
plugins/common.h.in

@@ -87,6 +87,22 @@
 # define strtoul(a,b,c) (unsigned long)atol((a))
 # define strtoul(a,b,c) (unsigned long)atol((a))
 #endif
 #endif
 
 
+#ifndef HAVE_ASPRINTF
+int asprintf(char **strp, const char *fmt, ...);
+#endif
+
+#ifndef HAVE_VASPRINTF
+/* int vasprintf(char **strp, const char *fmt, va_list ap); */
+#endif
+
+#ifndef HAVE_SNPRINTF
+int snprintf(char *str, size_t size, const  char  *format, ...);
+#endif
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
+#endif
+
 /*
 /*
  *
  *
  * Standard Values
  * Standard Values

+ 12 - 4
plugins/utils.c

@@ -44,6 +44,8 @@ int is_percentage (char *);
 
 
 int is_option (char *str);
 int is_option (char *str);
 
 
+double delta_time (struct timeval tv);
+
 void strip (char *);
 void strip (char *);
 char *strscpy (char *dest, const char *src);
 char *strscpy (char *dest, const char *src);
 char *strscat (char *dest, const char *src);
 char *strscat (char *dest, const char *src);
@@ -315,13 +317,21 @@ is_option (char *str)
 
 
 
 
 
 
+#ifndef HAVE_GETTIMEOFDAY
+int
+gettimeofday (struct timeval *tv, struct timezone *tz)
+{
+	tv->tv_usec = 0;
+	tv->tv_sec = (long) time ((time_t) 0);
+}
+#endif
+
+
 
 
 double
 double
 delta_time (struct timeval tv)
 delta_time (struct timeval tv)
 {
 {
 	struct timeval now;
 	struct timeval now;
-	struct timezone tz;
-	double et;
 
 
 	gettimeofday (&now, NULL);
 	gettimeofday (&now, NULL);
 	return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000);
 	return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000);
@@ -366,8 +376,6 @@ strip (char *buffer)
 char *
 char *
 strscpy (char *dest, const char *src)
 strscpy (char *dest, const char *src)
 {
 {
-	size_t len;
-
 	if (src == NULL)
 	if (src == NULL)
 		return NULL;
 		return NULL;
 
 

+ 4 - 5
plugins/utils.h.in

@@ -46,16 +46,15 @@ int is_percentage (char *);
 int is_option (char *);
 int is_option (char *);
 
 
 /* generalized timer that will do milliseconds if available */
 /* generalized timer that will do milliseconds if available */
-#ifndef HAVE_GETTIMEOFDAY
+#ifndef HAVE_STRUCT_TIMEVAL
 struct timeval {
 struct timeval {
 	long tv_sec;        /* seconds */
 	long tv_sec;        /* seconds */
 	long tv_usec;  /* microseconds */
 	long tv_usec;  /* microseconds */
 };
 };
+#endif
 
 
-#define gettimeofday (tvp,tz) {\
- tvp->tv_usec=0;\
- tvp->tv_sec=(long)time();\
-}
+#ifndef HAVE_GETTIMEOFDAY
+int gettimeofday(struct timeval *tv, struct timezone *tz);
 #endif
 #endif
 
 
 double delta_time (struct timeval tv);
 double delta_time (struct timeval tv);