diff --git a/configure.ac b/configure.ac index b4aa0082..fadc2951 100644 --- a/configure.ac +++ b/configure.ac @@ -111,6 +111,9 @@ AC_ARG_ENABLE(rrd_graph,AS_HELP_STRING([--disable-rrd_graph],[disable all rrd_gr AC_ARG_ENABLE(rrd_restore,AS_HELP_STRING([--disable-rrd_restore],[disable rrd_restore XML import functions]), [],[enable_rrd_restore=yes]) +AC_ARG_ENABLE(glib2,AS_HELP_STRING([--disable-glib2],[disable all glib2 functions]), +[],[enable_glib2=yes]) + AM_CONDITIONAL(BUILD_DOCS,[test $enable_docs != no]) AM_CONDITIONAL(BUILD_EXAMPLES,[test $enable_examples != no]) AM_CONDITIONAL(BUILD_RRDCGI,[test $enable_rrdcgi != no]) @@ -574,6 +577,11 @@ AM_CONDITIONAL(BUILD_RRDGRAPH,[test $enable_rrd_graph != no]) AM_CONDITIONAL(BUILD_RRDRESTORE,[test $enable_rrd_restore != no]) +if test $enable_glib2 != no; then + AC_DEFINE([HAVE_GLIB2], [], [is glib2 supported by this install]) +fi + +AS_IF([test "x$enable_glib2" != xno], [ EX_CHECK_ALL(glib-2.0, glib_check_version, glib.h, glib-2.0, 2.28.7, ftp://ftp.gtk.org/pub/glib/2.28/, "") AC_CACHE_CHECK([whether we need to include gthreads for g_thread_init], @@ -598,6 +606,14 @@ AC_CHECK_FUNC(g_regex_new,[ AC_MSG_ERROR([you need either glib with g_regex support or libpcre to compile rrdtool.]) ]) ]) +], [ + EX_CHECK_ALL(pcre, pcre_compile, pcre.h, pcre, x.x.x, [get a newer glib and you will not need pcre at all],"") + AC_CHECK_FUNC(pcre_compile,[ + AC_DEFINE(HAVE_PCRE_COMPILE,[1],[we have pcre to replace missing regexp support form glib]) + ],[ + AC_MSG_ERROR([you need either glib with g_regex support or libpcre to compile rrdtool.]) + ]) +]) diff --git a/src/rrd_create.c b/src/rrd_create.c index 0cb5b78c..122a2803 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -9,7 +9,9 @@ #include #include #include +#ifdef HAVE_GLIB2 #include // will use glist and regex +#endif @@ -56,11 +58,13 @@ static void reset_pdp_prep( rrd_t *rrd); static int rrd_init_data( rrd_t *rrd); +#ifdef HAVE_GLIB2 static int rrd_prefill_data( rrd_t *rrd, const GList *sources_rrd_files, mapping_t *mappings, int mappings_cnt); +#endif static int positive_mod( int a, int b); @@ -82,8 +86,10 @@ int rrd_create( {"start", 'b', OPTPARSE_REQUIRED}, {"step", 's', OPTPARSE_REQUIRED}, {"daemon", 'd', OPTPARSE_REQUIRED}, +#ifdef HAVE_GLIB2 {"source", 'r', OPTPARSE_REQUIRED}, {"template", 't', OPTPARSE_REQUIRED}, +#endif {"no-overwrite", 'O', OPTPARSE_NONE}, {0}, }; @@ -96,7 +102,9 @@ int rrd_create( int rc = -1; char *opt_daemon = NULL; int opt_no_overwrite = 0; +#ifdef HAVE_GLIB2 GList *sources = NULL; +#endif const char **sources_array = NULL; char *template = NULL; @@ -153,6 +161,7 @@ int rrd_create( opt_no_overwrite = 1; break; +#ifdef HAVE_GLIB2 case 'r':{ struct stat st; @@ -201,6 +210,7 @@ int rrd_create( template = optcpy; break; } +#endif case '?': rrd_set_error("%s", options.errmsg); rc = -1; @@ -213,6 +223,7 @@ int rrd_create( goto done; } +#ifdef HAVE_GLIB2 if (sources != NULL) { sources_array = malloc((g_list_length(sources) + 1) * sizeof(char *)); if (sources_array == NULL) { @@ -227,6 +238,7 @@ int rrd_create( } sources_array[n] = NULL; } +#endif rrdc_connect(opt_daemon); if (rrdc_is_connected(opt_daemon)) { rc = rrdc_create_r2(options.argv[options.optind], @@ -248,6 +260,7 @@ int rrd_create( free((char **) sources_array); /* Cast 'sources_array' from 'const char **' to 'char **' to avoid MSVC warning C4090 */ sources_array = NULL; } +#ifdef HAVE_GLIB2 if (sources != NULL) { // this will free the list elements as well g_list_free_full(sources, (GDestroyNotify) free); @@ -257,6 +270,7 @@ int rrd_create( free(template); template = NULL; } +#endif if (opt_daemon != NULL) { free(opt_daemon); } @@ -809,6 +823,7 @@ int rrd_create_r( } +#ifdef HAVE_GLIB2 static void cleanup_source_file( rrd_file_t *file) { @@ -823,6 +838,7 @@ static void cleanup_source_file( rrd_close(file); } +#endif int rrd_create_r2( const char *filename, @@ -839,7 +855,9 @@ int rrd_create_r2( unsigned long hashed_name; int rc = -1; struct stat stat_buf; +#ifdef HAVE_GLIB2 GList *sources_rrd_files = NULL; +#endif mapping_t *mappings = NULL; int mappings_cnt = 0; const char *require_version = NULL; @@ -1039,6 +1057,7 @@ int rrd_create_r2( rc = -1; // reset rc to default error state +#ifdef HAVE_GLIB2 if (sources != NULL) { time_t sources_latest_last_up = 0; @@ -1075,11 +1094,14 @@ int rrd_create_r2( } rrd_prefill_data(&rrd, sources_rrd_files, mappings, mappings_cnt); } +#endif rc = write_rrd(filename, &rrd); done: +#ifdef HAVE_GLIB2 g_list_free_full(sources_rrd_files, (GDestroyNotify) cleanup_source_file); +#endif if (mappings) { int ii; @@ -1586,6 +1608,7 @@ int write_fh( #undef FWRITE_CHECK } /* int write_file */ +#ifdef HAVE_GLIB2 static long overlap( time_t start1, time_t end1, @@ -2765,6 +2788,7 @@ static int rrd_prefill_data( return rc; } +#endif // calculate a % b, guaranteeing a positive result... static int positive_mod( diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 9c36eb1e..eb01b1f5 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -111,7 +111,9 @@ #endif /* HAVE_LIBWRAP */ #include "rrd_strtod.h" +#ifdef HAVE_GLIB2 #include +#endif /* }}} */ #define RRDD_LOG(severity, ...) \ diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 4df32ec6..7e87c72b 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -26,7 +26,9 @@ #include "rrd_tool.h" #include "rrd_rpncalc.h" +#ifdef HAVE_GLIB2 #include +#endif #define ALTYGRID 0x01 /* use alternative y grid algorithm */ diff --git a/src/rrd_update.c b/src/rrd_update.c index 831b8eed..b3f0845c 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -26,7 +26,9 @@ #include "rrd_client.h" #include "rrd_update.h" +#ifdef HAVE_GLIB2 #include +#endif #include "rrd_strtod.h" @@ -357,6 +359,7 @@ rrd_info_t *rrd_update_v( return result; } +#ifdef HAVE_GLIB2 static char *rrd_get_file_template(const char *filename) /* {{{ */ { rrd_t rrd; @@ -665,6 +668,7 @@ error: return ret; } /* }}} int rrd_template_update */ +#endif int rrd_update( int argc, @@ -672,7 +676,9 @@ int rrd_update( { struct optparse_long longopts[] = { {"template", 't', OPTPARSE_REQUIRED}, +#ifdef HAVE_GLIB2 {"daemon", 'd', OPTPARSE_REQUIRED}, +#endif {"skip-past-updates", 's', OPTPARSE_NONE}, {0}, }; @@ -698,6 +704,7 @@ int rrd_update( extra_flags |= RRD_SKIP_PAST_UPDATES; break; +#ifdef HAVE_GLIB2 case 'd': if (opt_daemon != NULL) { free (opt_daemon); @@ -709,6 +716,7 @@ int rrd_update( goto out; } break; +#endif case '?': rrd_set_error("%s", options.errmsg); @@ -729,7 +737,10 @@ int rrd_update( goto out; } } - +#ifndef HAVE_GLIB2 + rc = rrd_updatex_r(options.argv[options.optind], tmplt,extra_flags, + options.argc - options.optind - 1, (const char **) (options.argv + options.optind + 1)); +#else if (! rrdc_is_connected(opt_daemon)) { rc = rrd_updatex_r(options.argv[options.optind], tmplt,extra_flags, @@ -760,6 +771,7 @@ int rrd_update( rrd_set_error("Failed sending the values to rrdcached: %s", rrd_strerror (rc)); } +#endif out: if (tmplt != NULL) diff --git a/src/rrd_utils.c b/src/rrd_utils.c index cd0f80b0..0464e467 100644 --- a/src/rrd_utils.c +++ b/src/rrd_utils.c @@ -25,7 +25,9 @@ #include #include +#ifdef HAVE_GLIB2 #include +#endif #include #include #include @@ -284,8 +286,10 @@ const char * rrd_scaled_duration (const char * token, void rrd_thread_init(void) { +#ifdef HAVE_GLIB2 #if !GLIB_CHECK_VERSION(2, 32, 0) if (!g_thread_supported()) g_thread_init(NULL); #endif +#endif }