From d9188e538d16048047997a74af405cbb2871f353 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Wed, 16 Oct 2002 10:16:07 +0000 Subject: use asprintf git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@119 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/configure.in b/configure.in index ca890f7..6c98fe9 100644 --- a/configure.in +++ b/configure.in @@ -17,6 +17,13 @@ dnl Figure out how to invoke "install" and what install options to use. AC_PROG_INSTALL AC_SUBST(INSTALL) +AC_PROG_CC +AC_PROG_MAKE_SET +AC_PROG_AWK + +AC_FUNC_GETLOADAVG +AM_FUNC_STRTOD +AM_WITH_REGEX AC_PROG_RANLIB AC_PATH_PROG(ACLOCAL,aclocal) @@ -61,10 +68,6 @@ dnl PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/local/sbin:$ LDFLAGS="$LDFLAGS -L." dnl Checks for programs. -AC_PROG_CC -AC_PROG_MAKE_SET -AC_PROG_AWK - AC_PATH_PROG(PYTHON,python) AC_PATH_PROG(PERL,perl) AC_PATH_PROG(SH,sh) @@ -261,6 +264,7 @@ AC_HEADER_STDC AC_HEADER_TIME AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h unistd.h uio.h errno.h regex.h sys/types.h sys/time.h sys/socket.h sys/loadavg.h) +AC_CHECK_HEADERS(stdarg.h sys/unistd.h unistd.h ctype.h sys/wait.h stdlib.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -269,17 +273,65 @@ AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_SIGNAL -dnl AC_CHECK_MEMBER(struct timeb.millitm,[AC_DEFINE(HAVE_STRUCT_TIMEB_MILLITM)],,[#include ]) +AC_CHECK_SIZEOF(int,cross) +AC_CHECK_SIZEOF(long,cross) +AC_CHECK_SIZEOF(short,cross) -dnl EXTRA_LIBRARIES="libgetopt.a libsnprintf.a" -dnl noinst_LIBRARIES="libgetopt.a libsnprintf.a" -dnl libgetopt_a_SOURCES="getopt.c getopt1.c" -dnl libgetopt_a_DEPENDENCIES=getopt.h -dnl libsnprintf_a_SOURCES=snprintf.c -dnl AC_SUBST(noinst_LIBRARIES) -dnl AC_SUBST(libgetopt_a_SOURCES) -dnl AC_SUBST(libgetopt_a_DEPENDENCIES) -dnl AC_SUBST(libsnprintf_a_SOURCES) +AC_CACHE_CHECK([for long long],ac_cv_have_longlong,[ +AC_TRY_RUN([#include +main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }], +ac_cv_have_longlong=yes,ac_cv_have_longlong=no,ac_cv_have_longlong=cross)]) +if test x"$ac_cv_have_longlong" = x"yes"; then + AC_DEFINE(HAVE_LONGLONG) +fi + +# +# Check if the compiler supports the LL prefix on long long integers. +# AIX needs this. + +AC_CACHE_CHECK([for LL suffix on long long integers],ac_cv_compiler_supports_ll, [ + AC_TRY_COMPILE([#include ],[long long i = 0x8000000000LL], + ac_cv_compiler_supports_ll=yes,ac_cv_compiler_supports_ll=no)]) +if test x"$ac_cv_compiler_supports_ll" = x"yes"; then + AC_DEFINE(COMPILER_SUPPORTS_LL) +fi +AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE_VA_COPY,[ +AC_TRY_LINK([#include +va_list ap1,ap2;], [__va_copy(ap1,ap2);], +ac_cv_HAVE_VA_COPY=yes,ac_cv_HAVE_VA_COPY=no)]) +if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then + AC_DEFINE(HAVE_VA_COPY) +fi + +AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[ +AC_TRY_RUN([ +#include +#include +void foo(const char *format, ...) { + va_list ap; + int len; + char buf[5]; + + va_start(ap, format); + len = vsnprintf(buf, 0, format, ap); + va_end(ap); + if (len != 5) exit(1); + + va_start(ap, format); + len = vsnprintf(0, 0, format, ap); + va_end(ap); + if (len != 5) exit(1); + + if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1); + + exit(0); +} +main() { foo("hello"); } +], +ac_cv_HAVE_C99_VSNPRINTF=yes,ac_cv_HAVE_C99_VSNPRINTF=no,ac_cv_HAVE_C99_VSNPRINTF=cross)]) +if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then + AC_DEFINE(HAVE_C99_VSNPRINTF) +fi 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 @@ -302,7 +354,7 @@ AC_CHECK_FUNCS(getopt_long_only,,LIBS="$LIBS -lgetopt" DEPLIBS="$DEPLIBS libgeto AC_CHECK_FUNC(asprintf,,LIBS="$LIBS -lsnprintf" DEPLIBS="$DEPLIBS libsnprintf.a") dnl Checks for library functions. -AC_CHECK_FUNCS(select socket strdup strstr strtod strtol strtoul gettimeofday) +AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul gettimeofday) AC_MSG_CHECKING(for type of socket size) AC_TRY_COMPILE([#include diff --git a/plugins/check_http.c b/plugins/check_http.c index b3b2263..3ba406a 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -222,9 +222,9 @@ main (int argc, char **argv) if (strstr (timestamp, ":")) { if (strstr (server_url, "?")) - server_url = ssprintf (server_url, "%s&%s", server_url, timestamp); + asprintf (&server_url, "%s&%s", server_url, timestamp); else - server_url = ssprintf (server_url, "%s?%s", server_url, timestamp); + asprintf (&server_url, "%s?%s", server_url, timestamp); } if (display_html == TRUE) @@ -539,10 +539,8 @@ check_http (void) #ifdef HAVE_SSL if (use_ssl == TRUE) { - if (connect_SSL () != OK) { - msg = ssprintf (msg, "Unable to open TCP socket"); - terminate (STATE_CRITICAL, msg); - } + if (connect_SSL () != OK) + terminate (STATE_CRITICAL, "Unable to open TCP socket"); if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { X509_free (server_cert); @@ -552,7 +550,7 @@ check_http (void) return STATE_CRITICAL; } - buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url); + asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; @@ -560,7 +558,7 @@ check_http (void) /* optionally send the host header info (not clear if it's usable) */ if (strcmp (host_name, "")) { - buf = ssprintf (buf, "Host: %s\r\n", host_name); + asprintf (&buf, "Host: %s\r\n", host_name); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; @@ -568,7 +566,7 @@ check_http (void) } /* send user agent */ - buf = ssprintf (buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n", + asprintf (&buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n", clean_revstring (REVISION), PACKAGE_VERSION); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); @@ -578,7 +576,7 @@ check_http (void) /* optionally send the authentication info */ if (strcmp (user_auth, "")) { auth = base64 (user_auth, strlen (user_auth)); - buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth); + asprintf (&buf, "Authorization: Basic %s\r\n", auth); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; @@ -587,12 +585,12 @@ check_http (void) /* optionally send http POST data */ if (http_post_data) { - buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n"); + asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n"); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; } - buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); + asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; @@ -605,7 +603,7 @@ check_http (void) } /* send a newline so the server knows we're done with the request */ - buf = ssprintf (buf, "\r\n\r\n"); + asprintf (&buf, "\r\n\r\n"); if (SSL_write (ssl, buf, strlen (buf)) == -1) { ERR_print_errors_fp (stderr); return STATE_CRITICAL; @@ -614,23 +612,21 @@ check_http (void) } else { #endif - if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) { - msg = ssprintf (msg, "Unable to open TCP socket"); - terminate (STATE_CRITICAL, msg); - } - buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url); + if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) + terminate (STATE_CRITICAL, "Unable to open TCP socket"); + asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); send (sd, buf, strlen (buf), 0); /* optionally send the host header info */ if (strcmp (host_name, "")) { - buf = ssprintf (buf, "Host: %s\r\n", host_name); + asprintf (&buf, "Host: %s\r\n", host_name); send (sd, buf, strlen (buf), 0); } /* send user agent */ - buf = ssprintf (buf, + asprintf (&buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n", clean_revstring (REVISION), PACKAGE_VERSION); send (sd, buf, strlen (buf), 0); @@ -638,23 +634,23 @@ check_http (void) /* optionally send the authentication info */ if (strcmp (user_auth, "")) { auth = base64 (user_auth, strlen (user_auth)); - buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth); + asprintf (&buf, "Authorization: Basic %s\r\n", auth); send (sd, buf, strlen (buf), 0); } /* optionally send http POST data */ /* written by Chris Henesy */ if (http_post_data) { - buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n"); + asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n"); send (sd, buf, strlen (buf), 0); - buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); + asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); send (sd, buf, strlen (buf), 0); http_post_data = strscat (http_post_data, "\r\n"); send (sd, http_post_data, strlen (http_post_data), 0); } /* send a newline so the server knows we're done with the request */ - buf = ssprintf (buf, "\r\n\r\n"); + asprintf (&buf, "\r\n\r\n"); send (sd, buf, strlen (buf), 0); #ifdef HAVE_SSL } @@ -663,7 +659,7 @@ check_http (void) /* fetch the page */ pagesize = (size_t) 0; while ((i = my_recv ()) > 0) { - buffer[i] = "\0"; + buffer[i] = '\0'; full_page = strscat (full_page, buffer); pagesize += i; } @@ -716,9 +712,9 @@ check_http (void) /* make sure the status line matches the response we are looking for */ if (!strstr (status_line, server_expect)) { if (server_port == HTTP_PORT) - msg = ssprintf (msg, "Invalid HTTP response received from host\n"); + asprintf (&msg, "Invalid HTTP response received from host\n"); else - msg = ssprintf (msg, + asprintf (&msg, "Invalid HTTP response received from host on port %d\n", server_port); terminate (STATE_CRITICAL, msg); @@ -727,7 +723,7 @@ check_http (void) /* Exit here if server_expect was set by user and not default */ if ( server_expect_yn ) { - msg = ssprintf (msg, "HTTP OK: Status line output matched \"%s\"\n", + asprintf (&msg, "HTTP OK: Status line output matched \"%s\"\n", server_expect); if (verbose) printf ("%s\n",msg); @@ -742,8 +738,7 @@ check_http (void) strstr (status_line, "501") || strstr (status_line, "502") || strstr (status_line, "503")) { - msg = ssprintf (msg, "HTTP CRITICAL: %s\n", status_line); - terminate (STATE_CRITICAL, msg); + terminate (STATE_CRITICAL, "HTTP CRITICAL: %s\n", status_line); } /* client errors result in a warning state */ @@ -752,8 +747,7 @@ check_http (void) strstr (status_line, "402") || strstr (status_line, "403") || strstr (status_line, "404")) { - msg = ssprintf (msg, "HTTP WARNING: %s\n", status_line); - terminate (STATE_WARNING, msg); + terminate (STATE_WARNING, "HTTP WARNING: %s\n", status_line); } /* check redirected page if specified */ @@ -807,7 +801,7 @@ check_http (void) else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) { if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) { *x = '\0'; - server_url = ssprintf (server_url, "%s/%s", orig_url, server_url); + asprintf (&server_url, "%s/%s", orig_url, server_url); } check_http (); } @@ -828,7 +822,7 @@ check_http (void) else if (onredirect == STATE_CRITICAL) printf ("HTTP CRITICAL"); time (&end_time); - msg = ssprintf (msg, ": %s - %d second response time %s%s|time=%d\n", + asprintf (&msg, ": %s - %d second response time %s%s|time=%d\n", status_line, (int) (end_time - start_time), timestamp, (display_html ? "" : ""), (int) (end_time - start_time)); terminate (onredirect, msg); @@ -840,7 +834,7 @@ check_http (void) /* check elapsed time */ time (&end_time); - msg = ssprintf (msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n", + asprintf (&msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n", status_line, (int) (end_time - start_time), timestamp, (display_html ? "" : ""), (int) (end_time - start_time)); if (check_critical_time == TRUE && (end_time - start_time) > critical_time) @@ -889,7 +883,7 @@ check_http (void) #endif /* We only get here if all tests have been passed */ - msg = ssprintf (msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n", + asprintf (&msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n", status_line, (int) (end_time - start_time), timestamp, (display_html ? "" : ""), (int) (end_time - start_time)); terminate (STATE_OK, msg); -- cgit v0.10-9-g596f