* Fixed invalid AC_LANG_PROGRAM usage.
* Fixed AUTOMAKE_OPTIONS not defining subdir-objects which caused warnings
* Switched from legacy INCLUDES to AM_CPPFLAGS
* Added Makefile clean targets to ensure all autogenerated targets are removed
* Updated Makefile.PL to be more portable and less hardcoded for Win32
* Switched bash scripts to use #!/usr/bin/env bash for compatibility with none Linux OS's
* Cleaned up win32/Makefile.msc variable defines for easy updating
* Updated defines of SIZEOF_TIME_T to take into account the variances in Windows.
== Code Enhancements / fixes ==
* Added support for rrdcached client methods to windows builds
* Fixed invalid type warning for atoi assignment to a enum
* Fixed malloc cast warnings
* Fixed illegal use of this for variable
* Fixed getsockname cast warning
* Removed HAVE_CONFIG_H checks as all platforms now have it
* Removed unused skip variable from rrd_graph data_fetch
* Fixed unused var warnings for newGraphDescription params
* Fixed unused var st warning in HandleInputLine
* Fixed all includes for <stdint.h> to check HAVE_STDINT_H
* Fixed use of uninitialsed base_dir in rrd_mkdir_p on Win32
* Updated win32/README with details of obtaining stdint.h as well as locations
for dependencies
-#!/bin/bash
+#!/usr/bin/env bash
#
# Run this script after the first cvs checkout to build
# makefiles and friends
libtool \
netware/Makefile \
etc/rrdcached-default etc/rrdcached-init \
- win32/Makefile win32/config.h win32/rrdlib.vcproj win32/rrdtool.vcproj win32/rrdupdate.vcproj \
- win32/README win32/rrd.sln win32/rrdtool.sln win32/rrdupdate.sln
+ win32/Makefile win32/rrd_config.h win32/rrdlib.vcproj win32/rrdtool.vcproj win32/rrdupdate.vcproj \
+ win32/README win32/rrd.sln win32/rrdtool.sln win32/rrdupdate.sln win32/Makefile.msc
CLEANFILES = config.cache
indent:
find ./ -name "*.[ch]" | xargs indent
+clean-local:
+ -rm -f config.h bindings/perl-piped/Makefile.old bindings/perl-shared/Makefile.old
+
##END##
-#!/bin/bash
+#!/usr/bin/env bash
# On MAC OS X, GNU libtoolize is named 'glibtoolize':
if [ `(uname -s) 2>/dev/null` == 'Darwin' ]
# it's not already installed.
EXTRA_DIST = README test.lua.bottom compat-5.1r5/compat-5.1.lua
+AUTOMAKE_OPTIONS = subdir-objects
+
LIB_VERSION_INFO=0:0:0
LUA = @LUA@
# the contents of the Makefile that is written.
if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '')) {
+ my ($perlver) = ($] =~ /(\d+\.\d{3})/);
+ $perlver =~ s/[.0]//g;
+
+ my $perl_core_dir = "$Config{privlib}/CORE";
+ my $vc_dir = $ENV{'VSINSTALLDIR'} || 'C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC';
+ my $sdk_dir = $ENV{'WindowsSdkDir'} || 'C:/Program Files/Microsoft SDKs/Windows/v6.0A';
+
WriteMakefile(
'NAME' => 'RRDs',
'VERSION_FROM' => 'RRDs.pm',
'DEFINE' => "-DPERLPATCHLEVEL=$Config{PATCHLEVEL} -D_CRT_SECURE_NO_WARNINGS -DWIN32",
- 'INC' => '-I../../src/ "-IC:/Perl/lib/CORE" -I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" -I"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include"',
- 'LDDLFLAGS' => '-dll -nologo -opt:ref,icf -ltcg -libpath:"C:\Perl\lib\CORE" -machine:X86',
- 'LDFLAGS' => '-nologo -opt:ref,icf -ltcg -libpath:"C:\Perl\lib\CORE" -machine:X86',
+ 'INC' => '-I../../src -I../../win32 "-I$perl_core_dir" -I"$vc_dir/include" -I"$sdk_dir/Include"',
+ 'LDDLFLAGS' => '-dll -nologo -opt:ref,icf -ltcg -libpath:"$perl_core_dir" -machine:X86',
+ 'LDFLAGS' => '-nologo -opt:ref,icf -ltcg -libpath:"$perl_core_dir" -machine:X86',
'OPTIMIZE' => '-O2 -MD',
- 'LIBS' => '"..\..\win32\Release\rrdlib.lib" "..\..\win32\Release" "C:\Perl\lib\CORE\perl514.lib" -L../../contrib/lib -L"C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib" -L"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib" -L"C:\Perl\lib\CORE"',
+ 'LIBS' => qq{"../../win32/librrd-4.lib" "perl$perlver.lib" -L../../contrib/lib -L../../win32 -L"$sdk_dir/lib" -L"$vc_dir/lib" -L"$perl_core_dir"},
'realclean' => {FILES => 't/demo?.rrd t/demo?.png' },
($] ge '5.005') ? (
'AUTHOR' => 'Tobias Oetiker (tobi@oetiker.ch)',
OUTPUT:
RETVAL
-#ifndef WIN32
int
rrd_flushcached(...)
PROTOTYPE: @
rrdcode(rrd_flushcached);
OUTPUT:
RETVAL
-
-#endif
dnl solaris has some odd defines it needs in order to propperly compile ctime_r
AC_MSG_CHECKING([if ctime_r need special care to act posixly correct])
AC_LINK_IFELSE(
- AC_LANG_PROGRAM(
+ [AC_LANG_PROGRAM(
[[#include <time.h>]],
- [[ctime_r(NULL,NULL,0)]]
- ),
+ [[ctime_r(NULL,NULL,0)]])],
[ CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
AC_LINK_IFELSE(
- AC_LANG_PROGRAM(
+ [AC_LANG_PROGRAM(
[[#include <time.h>]],
- [[ctime_r(NULL,NULL)]]
- ),
+ [[ctime_r(NULL,NULL)]])],
[AC_MSG_RESULT([yes, this seems to be solaris style])],
[AC_MSG_ERROR([Can't figure how to compile ctime_r])]
)
],
[ AC_LINK_IFELSE(
- AC_LANG_PROGRAM(
+ [AC_LANG_PROGRAM(
[[#include <time.h>]],
- [[ctime_r(NULL,NULL)]]
- ),
+ [[ctime_r(NULL,NULL)]])],
[AC_MSG_RESULT(no)],
[AC_MSG_ERROR([Can't figure how to compile ctime_r])]
)
dnl see if we have to include malloc/malloc.h
AC_MSG_CHECKING([do we need malloc/malloc.h])
AC_LINK_IFELSE(
- AC_LANG_PROGRAM(
+ [AC_LANG_PROGRAM(
[[#include <stdlib.h>]],
- [[malloc(1)]]
- ),
+ [[malloc(1)]])],
[ AC_MSG_RESULT([nope, works out of the box]) ],
[ AC_LINK_IFELSE(
- AC_LANG_PROGRAM(
+ [AC_LANG_PROGRAM(
[[#include <stdlib.h>
#include <malloc/malloc.h>]],
- [[malloc(1)]]
- ),[
- AC_DEFINE([MUST_HAVE_MALLOC_MALLOC_H])
+ [[malloc(1)]])],
+ [AC_DEFINE([MUST_HAVE_MALLOC_MALLOC_H])
AC_MSG_RESULT([yes we do])],
[AC_MSG_ERROR([Can not figure how to compile malloc])]
)
sed 's,@''exec_prefix@,$(exec_prefix),' @srcdir@/cgi-demo.cgi.in > $@
chmod a+x $@
+clean-local:
+ -rm -f cgi-demo.cgi
AM_LDFLAGS = -all-static
endif
-INCLUDES = -DLOCALEDIR="\"$(datadir)/locale\""
RRD_DEFAULT_FONT=@RRD_DEFAULT_FONT@
-AM_CPPFLAGS = -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" -DNUMVERS=@NUMVERS@
+AM_CPPFLAGS = -DLOCALEDIR="\"$(datadir)/locale\"" \
+ -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" \
+ -DNUMVERS=@NUMVERS@
AM_CFLAGS = @CFLAGS@ -I$(top_srcdir)
## no including this by default @WERROR@
UPD_C_FILES = \
+ mutex.c \
rrd_create.c \
hash_32.c \
rrd_parsetime.c \
noinst_HEADERS = \
unused.h \
gettext.h \
+ mutex.h \
rrd_getopt.h rrd_parsetime.h \
rrd_config_bottom.h rrd_i18n.h \
rrd_format.h rrd_tool.h rrd_xport.h rrd.h rrd_rpncalc.h \
install-exec-hook:
(cd $(DESTDIR)$(bindir) && $(LN_S) rrdupdate rrdcreate && $(LN_S) rrdupdate rrdinfo) || true
+
+distclean-local:
+ -rm -rf rrd_config.h librrd.sym
--- /dev/null
+/*
+ *
+ * mutex.c
+ *
+ * Cross platform mutex
+ *
+ */
+
+#include "mutex.h"
+
+int mutex_init(mutex_t *mutex)
+{
+#ifdef WIN32
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ return (*mutex == NULL);
+#else
+ return pthread_mutex_init(mutex, NULL);;
+#endif
+}
+
+int mutex_lock(mutex_t *mutex)
+{
+#ifdef WIN32
+ if (*mutex == NULL) { /* static initializer? */
+ HANDLE p = CreateMutex(NULL, FALSE, NULL);
+ if (InterlockedCompareExchangePointer((PVOID*)mutex, (PVOID)p, NULL) != NULL)
+ CloseHandle(p);
+ }
+ return (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED);
+#else
+ return pthread_mutex_lock(mutex);
+#endif
+}
+
+int mutex_unlock(mutex_t *mutex)
+{
+#ifdef WIN32
+ return (ReleaseMutex(*mutex) == 0);
+#else
+ return pthread_mutex_unlock(mutex);
+#endif
+}
+
+int mutex_cleanup(mutex_t *mutex)
+{
+#ifdef WIN32
+ return (CloseHandle(mutex) == 0);
+#else
+ return pthread_mutex_destroy(mutex);
+#endif
+}
+
+/*
+ * vim: set sw=2 sts=2 ts=8 et fdm=marker :
+ */
+
--- /dev/null
+/*
+ * mutex.h - Cross platform mutex
+ */
+
+#ifndef MUTEX__H
+#define MUTEX__H
+
+#ifdef WIN32
+#include <windows.h>
+#include <process.h>
+#else
+#include <pthread.h>
+#endif
+
+#ifndef WIN32
+#define mutex_t pthread_mutex_t
+#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#else
+#define mutex_t HANDLE
+#define MUTEX_INITIALIZER NULL
+#endif
+
+int mutex_init(mutex_t *mutex);
+int mutex_lock(mutex_t *mutex);
+int mutex_unlock(mutex_t *mutex);
+int mutex_cleanup(mutex_t *mutex);
+
+#endif /* MUTEX__H */
+
+/*
+ * vim: set sw=2 sts=2 ts=8 et fdm=marker :
+ */
+
#include <stdlib.h>
#endif
-#ifdef WIN32
- #define strcasecmp stricmp
- #define strcasencmp strnicmp
-#endif
-
#define MEMBLK 1024
/*#define DEBUG_PARSER
#define DEBUG_VARS*/
* Sebastian tokkee Harl <sh at tokkee.org>
**/
+#ifdef WIN32
+#include <time.h>
+#include <ws2tcpip.h>
+#include <winsock2.h>
+#include <io.h>
+#include <fcntl.h>
+#include <tchar.h>
+#include <locale.h>
+#endif
+
#include "rrd.h"
#include "rrd_tool.h"
#include "rrd_client.h"
+#include "mutex.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
#include <errno.h>
#include <assert.h>
+#ifndef WIN32
+#include <strings.h>
#include <pthread.h>
-#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
-#include <limits.h>
#include <locale.h>
-
-#ifndef ENODATA
-#define ENODATA ENOENT
#endif
+#include <sys/types.h>
+#include <limits.h>
struct rrdc_response_s
{
};
typedef struct rrdc_response_s rrdc_response_t;
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static mutex_t lock = MUTEX_INITIALIZER;
static int sd = -1;
-static FILE *sh = NULL;
static char *sd_path = NULL; /* cache the path for sd */
+static char _inbuf[RRD_CMD_MAX];
+static char *inbuf = _inbuf;
+static size_t inbuf_used = 0;
+
/* get_path: Return a path name appropriate to be sent to the daemon.
*
* When talking to a local daemon (thru a UNIX socket), relative path names
static int parse_char_array_header (char *line, /* {{{ */
char **ret_key, char **array, size_t array_len, int alloc)
{
- char *tmp_array[array_len];
+ char **tmp_array;
char *value;
size_t num;
int status;
+ if ((tmp_array = (char**)malloc(array_len * sizeof (char*))) == NULL)
+ return (-1);
+
value = NULL;
status = parse_header (line, ret_key, &value);
- if (status != 0)
+ if (status != 0) {
+ free(tmp_array);
return (-1);
+ }
num = strsplit (value, tmp_array, array_len);
if (num != array_len)
+ {
+ free(tmp_array);
return (-1);
+ }
if (alloc == 0)
{
array[i] = strdup (tmp_array[i]);
}
+ free(tmp_array);
+
return (0);
} /* }}} int parse_char_array_header */
time_t *ret_time, rrd_value_t *array, size_t array_len)
{
char *str_key;
- char *str_array[array_len];
+ char **str_array;
char *endptr;
char *old_locale;
int status;
size_t i;
+ if ((str_array = (char**)malloc(array_len * sizeof (char*))) == NULL)
+ return (-1);
+
str_key = NULL;
status = parse_char_array_header (line, &str_key,
str_array, array_len, /* alloc = */ 0);
- if (status != 0)
+ if (status != 0) {
+ free(str_array);
return (-1);
+ }
errno = 0;
endptr = NULL;
*ret_time = (time_t) strtol (str_key, &endptr, /* base = */ 10);
- if ((endptr == str_key) || (errno != 0))
+ if ((endptr == str_key) || (errno != 0)) {
+ free(str_array);
return (-1);
+ }
/* Enforce the "C" locale so that parsing of the response is not dependent on
* the locale. For example, when using a German locale the strtod() function
if ((endptr == str_array[i]) || (errno != 0))
{
(void) setlocale (LC_NUMERIC, old_locale);
+ free(str_array);
return (-1);
}
}
(void) setlocale (LC_NUMERIC, old_locale);
+ free(str_array);
return (0);
} /* }}} int parse_value_array_header */
/* One must hold `lock' when calling `close_connection'. */
static void close_connection (void) /* {{{ */
{
- if (sh != NULL)
- {
- fclose (sh);
- sh = NULL;
- sd = -1;
- }
- else if (sd >= 0)
+ if (sd >= 0)
{
+#ifdef WIN32
+ closesocket(sd);
+ WSACleanup();
+#else
close (sd);
+#endif
sd = -1;
}
free (res);
} /* }}} void response_free */
+static int recvline (char *buf, size_t n) /* {{{ */
+{
+ size_t len;
+ char *s, *p, *t;
+
+ /* Sanity check */
+ if (n <= 0)
+ return (-1);
+
+ s = buf;
+ n--; /* leave space for the NULL */
+ while (n != 0)
+ {
+ /*
+ * If the buffer is empty, refill it.
+ */
+ if ((len = inbuf_used) <= 0)
+ {
+ inbuf = _inbuf;
+ inbuf_used = recv (sd, inbuf, RRD_CMD_MAX, 0);
+ if (inbuf_used <= 0)
+ {
+ if (s == buf)
+ {
+ /* EOF/error: stop with partial or no line */
+ return (-1);
+ }
+ }
+ len = inbuf_used;
+ }
+ p = inbuf;
+ /*
+ * Scan through at most n bytes of the current buffer,
+ * looking for '\n'. If found, copy up to and including
+ * newline, and stop. Otherwise, copy entire chunk
+ * and loop.
+ */
+ if (len > n)
+ len = n;
+ t = (char*)memchr((void *)p, '\n', len);
+ if (t != NULL)
+ {
+ len = ++t - p;
+ inbuf_used -= len;
+ inbuf = t;
+ (void)memcpy((void *)s, (void *)p, len);
+ s[len] = 0;
+ return (1);
+ }
+ inbuf_used -= len;
+ inbuf += len;
+ (void)memcpy((void *)s, (void *)p, len);
+ s += len;
+ n -= len;
+ }
+ *s = 0;
+ return (1);
+} /* }}} int recvline */
+
static int response_read (rrdc_response_t **ret_response) /* {{{ */
{
rrdc_response_t *ret = NULL;
int status = 0;
char buffer[RRD_CMD_MAX];
- char *buffer_ptr;
size_t i;
#define DIE(code) do { status = code; goto err_out; } while(0)
- if (sh == NULL)
+ if (sd == -1)
DIE(-1);
ret = (rrdc_response_t *) malloc (sizeof (rrdc_response_t));
ret->lines = NULL;
ret->lines_num = 0;
- buffer_ptr = fgets (buffer, sizeof (buffer), sh);
- if (buffer_ptr == NULL)
+ if (recvline (buffer, sizeof (buffer)) == -1)
DIE(-3);
chomp (buffer);
for (i = 0; i < ret->lines_num; i++)
{
- buffer_ptr = fgets (buffer, sizeof (buffer), sh);
- if (buffer_ptr == NULL)
+ if (recvline (buffer, sizeof (buffer)) == -1)
DIE(-6);
chomp (buffer);
out:
*ret_response = ret;
- fflush(sh);
return (status);
err_out:
} /* }}} rrdc_response_t *response_read */
+static int sendall (const char *msg, size_t len) /* {{{ */
+{
+ int ret = 0;
+ char *bufp = (char*)msg;
+
+ while (ret != -1 && len > 0) {
+ ret = send(sd, msg, len, 0);
+ if (ret > 0) {
+ bufp += ret;
+ len -= ret;
+ }
+ }
+
+ return ret;
+} /* }}} int sendall */
+
static int request (const char *buffer, size_t buffer_size, /* {{{ */
rrdc_response_t **ret_response)
{
int status;
rrdc_response_t *res;
- if (sh == NULL)
+ if (sd == -1)
return (ENOTCONN);
- status = (int) fwrite (buffer, buffer_size, /* nmemb = */ 1, sh);
- if (status != 1)
+ status = sendall (buffer, buffer_size);
+ if (status == -1)
{
close_connection ();
rrd_set_error("request: socket error (%d) while talking to rrdcached",
status);
return (-1);
}
- fflush (sh);
res = NULL;
status = response_read (&res);
static int rrdc_connect_unix (const char *path) /* {{{ */
{
+#ifdef WIN32
+ return (WSAEPROTONOSUPPORT);
+#else
struct sockaddr_un sa;
int status;
return (status);
}
- sh = fdopen (sd, "r+");
- if (sh == NULL)
- {
- status = errno;
- close_connection ();
- return (status);
- }
-
return (0);
+#endif
} /* }}} int rrdc_connect_unix */
static int rrdc_connect_network (const char *addr_orig) /* {{{ */
} /* if (*addr == '[') */
else
{
- port = rindex(addr, ':');
+ port = strrchr(addr, ':');
if (port != NULL)
{
*port = 0;
}
}
+#ifdef WIN32
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ wVersionRequested = MAKEWORD(2, 0);
+ status = WSAStartup(wVersionRequested, &wsaData);
+ if (status != 0)
+ {
+ rrd_set_error("failed to initialise socket library %d", status);
+ return (-1);
+ }
+#endif
+
ai_res = NULL;
status = getaddrinfo (addr,
port == NULL ? RRDCACHED_DEFAULT_PORT : port,
&ai_hints, &ai_res);
if (status != 0)
{
- rrd_set_error ("failed to resolve address `%s' (port %s): %s",
+ rrd_set_error ("failed to resolve address '%s' (port %s): %s (%d)",
addr, port == NULL ? RRDCACHED_DEFAULT_PORT : port,
- gai_strerror (status));
+ gai_strerror (status), status);
return (-1);
}
close_connection();
continue;
}
-
- sh = fdopen (sd, "r+");
- if (sh == NULL)
- {
- status = errno;
- close_connection ();
- continue;
- }
-
assert (status == 0);
break;
} /* for (ai_ptr) */
return 0;
}
- pthread_mutex_lock(&lock);
+ mutex_lock (&lock);
if (sd >= 0 && sd_path != NULL && strcmp(addr, sd_path) == 0)
{
/* connection to the same daemon; use cached connection */
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (0);
}
else
free (err);
}
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (status);
} /* }}} int rrdc_connect */
int rrdc_disconnect (void) /* {{{ */
{
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
close_connection();
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (0);
} /* }}} int rrdc_disconnect */
if (status != 0)
return (ENOBUFS);
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (-1);
}
status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (ENOBUFS);
}
status = buffer_add_value (values[i], &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (ENOBUFS);
}
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0)
return (status);
if (status != 0)
return (ENOBUFS);
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (-1);
}
status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (ENOBUFS);
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0)
return (status);
return (NULL);
}
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (NULL);
}
status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_info: out of memory");
return (NULL);
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0) {
rrd_set_error ("rrdcached: %s", res->message);
if(*s == ' ') { *s = 0; s++; break; }
}
if(!s || !*s) break;
- itype = atoi(s); /* extract type code */
+ itype = (rrd_info_type_t)atoi(s); /* extract type code */
for(;*s;s++) { if(*s == ' ') { *s = 0; s++; break; } }
if(!*s) break;
/* finally, we're pointing to the value */
rrd_set_error ("rrdc_info: Unsupported info type %d",itype);
return (NULL);
}
-
+
cd = rrd_info_push(cd, sprintf_alloc("%s",k), itype, info);
if(!data) data = cd;
}
return (-1);
}
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (-1);
}
status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_last: out of memory");
return (-1);
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0) {
rrd_set_error ("rrdcached: %s", res->message);
return (-1);
}
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (-1);
}
status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_first: out of memory");
return (-1);
}
status = buffer_add_ulong (rraindex, &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_first: out of memory");
return (-1);
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0) {
rrd_set_error ("rrdcached: %s", res->message);
return (-1);
}
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
filename = get_path (filename, file_path);
if (filename == NULL)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
return (-1);
}
}
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_create: out of memory");
return (-1);
}
status = buffer_add_string (argv[i], &buffer_ptr, &buffer_free);
if (status != 0)
{
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
rrd_set_error ("rrdc_create: out of memory");
return (-1);
}
res = NULL;
status = request (buffer, buffer_size, &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0) {
rrd_set_error ("rrdcached: %s", res->message);
READ_NUMERIC_FIELD ("DSCount", unsigned long, ds_num);
if (ds_num < 1)
BAIL_OUT (-1, "Invalid number for DSCount: %lu", ds_num);
-
+
/* It's time to allocate some memory */
- ds_names = calloc ((size_t) ds_num, sizeof (*ds_names));
+ ds_names = (char **)calloc ((size_t) ds_num, sizeof (*ds_names));
if (ds_names == NULL)
BAIL_OUT (-1, "Out of memory");
BAIL_OUT (-1, "Got %zu lines, expected %zu",
res->lines_num, (6 + (data_size / ds_num)));
- data = calloc (data_size, sizeof (*data));
+ data = (rrd_value_t *)calloc (data_size, sizeof (*data));
if (data == NULL)
BAIL_OUT (-1, "Out of memory");
-
+
data_fill = 0;
for (t = start + step; t <= end; t += step, current_line++)
* }}} */
res = NULL;
- pthread_mutex_lock (&lock);
+ mutex_lock (&lock);
status = request ("STATS\n", strlen ("STATS\n"), &res);
- pthread_mutex_unlock (&lock);
+ mutex_unlock (&lock);
if (status != 0)
return (status);
void rrdc_stats_free (rrdc_stats_t *ret_stats) /* {{{ */
{
- rrdc_stats_t *this;
+ rrdc_stats_t *stats;
- this = ret_stats;
- while (this != NULL)
+ stats = ret_stats;
+ while (stats != NULL)
{
rrdc_stats_t *next;
- next = this->next;
+ next = stats->next;
- if (this->name != NULL)
+ if (stats->name != NULL)
{
- free ((char *)this->name);
- this->name = NULL;
+ free ((char *)stats->name);
+ stats->name = NULL;
}
- free (this);
+ free (stats);
- this = next;
+ stats = next;
} /* while (this != NULL) */
} /* }}} void rrdc_stats_free */
# include <stdint.h>
# endif
-# ifdef HAVE_INTTYPES_H
-# include <inttypes.h>
-# endif
-
-# if !(defined(HAVE_STDINT_H) || defined(HAVE_INTTYPES_H))
-# include <stdlib.h>
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- typedef signed int int16_t;
- typedef unsigned int uint16_t;
- typedef signed long int int32_t;
- typedef unsigned long int uint32_t;
- typedef signed long long int int64_t;
- typedef unsigned long long int uint64_t;
-# endif
-
/* max length of socket command or response */
#define RRD_CMD_MAX 4096
#define ENV_RRDCACHED_ADDRESS "RRDCACHED_ADDRESS"
-// Windows version has no daemon/client support
-
-#ifndef WIN32
int rrdc_connect (const char *addr);
int rrdc_is_connected(const char *daemon_addr);
int rrdc_disconnect (void);
int rrdc_update (const char *filename, int values_num,
- const char * const *values);
+ const char * const *values);
rrd_info_t * rrdc_info (const char *filename);
time_t rrdc_last (const char *filename);
char ***ret_ds_names,
rrd_value_t **ret_data);
-#else
-# define rrdc_create(a,b,c,d,e,f) 0
-# define rrdc_flush_if_daemon(a,b) 0
-# define rrdc_connect(a) 0
-# define rrdc_is_connected(a) 0
-# define rrdc_flush(a) 0
-# define rrdc_update(a,b,c) 0
-# define rrdc_last(a) 0
-# define rrdc_first(a,b) 0
-# define rrdc_fetch(a,b,c,d,e,f,g,h) 0
-# define rrdc_info(a) 0
-#endif
-
struct rrdc_stats_s
{
const char *name;
#include "unused.h"
#include <stdlib.h>
-
-#ifndef WIN32
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
+
+#ifndef WIN32
#include <unistd.h>
#include <strings.h>
#include <inttypes.h>
l = sizeof(sa);
memset(&sa, 0, l);
- if (getsockname(sd_fd, &sa, &l) < 0)
+ if (getsockname(sd_fd, (struct sockaddr *)&sa, &l) < 0)
{
fprintf(stderr, "open_listen_sockets_systemd: problem getting fd %d: %s\n", sd_fd, rrd_strerror (errno));
return i;
if (! rrdc_is_connected(opt_daemon))
{
- rrd_set_error ("Daemon address unknown. Please use the \"--daemon\" "
+ rrd_set_error ("Daemon address \"%s\" unknown. Please use the \"--daemon\" "
"option to set an address on the command line or set the "
"\"%s\" environment variable.",
+ opt_daemon,
ENV_RRDCACHED_ADDRESS);
status = -1;
goto out;
#endif
#endif
-#ifndef WIN32
-#ifdef HAVE_CONFIG_H
-#include "../rrd_config.h"
-#endif
-#endif
-
+#include "rrd_config.h"
#include "rrd_i18n.h"
#endif
#endif
-#ifndef WIN32
-#ifdef HAVE_CONFIG_H
-#include "../rrd_config.h"
-#endif
-#endif
-
+#include "rrd_config.h"
#include "rrd_getopt.h"
#include <stdio.h>
image_desc_t *im)
{
int i, ii;
- int skip;
/* pull the data from the rrd files ... */
for (i = 0; i < (int) im->gdes_c; i++) {
/* only GF_DEF elements fetch data */
****************************************************************************/
#include <locale.h>
+#include "rrd_config.h"
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
#include "rrd_graph.h"
if ((start)&&(parsetime_error = rrd_parsetime(start, &start_tv))) {
rrd_set_error("start time: %s", parsetime_error);return NULL; }
dprintfparsed("got start: %s\n",start);
+ } else {
+ start = NULL;
}
/* now end */
char* end;
if ((end)&&(parsetime_error = rrd_parsetime(end, &end_tv))) {
rrd_set_error("end time: %s", parsetime_error); return NULL; }
dprintfparsed("got end: %s\n",end);
+ } else {
+ end = NULL;
}
/* and now put the pieces together (relative times like start=end-2days) */
time_t start_tmp = 0, end_tmp = 0;
/* and other stuff */
a->bounds.lowertxt=getKeyValueArgument("min",1,pa);
a->bounds.uppertxt=getKeyValueArgument("max",1,pa);
+#else
+ /* prevent unused warnings */
+ (void)gf;
+ (void)pa;
+ (void)im;
#endif
/* and return */
#include "rrd_config.h"
-#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) && !defined(HAVE_CONFIG_H)
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
#include <stdlib.h>
#include <sys/stat.h>
#include <io.h>
DIR *curdir; /* to read current dir with ls */
struct dirent *dent;
#endif
-#if defined(HAVE_SYS_STAT_H)
- struct stat st;
-#endif
/* Reset errno to 0 before we start.
*/
}
exit(0);
}
-#if defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_CHDIR)
+#if defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_CHDIR) && defined(HAVE_SYS_STAT_H)
if (argc > 1 && strcmp("cd", argv[1]) == 0) {
if (argc != 3) {
printf("ERROR: invalid parameter count for cd\n");
return (1);
}
if ((curdir = opendir(".")) != NULL) {
+ struct stat st;
while ((dent = readdir(curdir)) != NULL) {
if (!stat(dent->d_name, &st)) {
if (S_ISDIR(st.st_mode)) {
#endif
} else if (strcmp("tune", argv[1]) == 0)
rrd_tune(argc - 1, &argv[1]);
-#ifndef WIN32
else if (strcmp("flushcached", argv[1]) == 0)
rrd_flushcached(argc - 1, &argv[1]);
-#endif
else {
rrd_set_error("unknown function '%s'", argv[1]);
}
#endif
#include <locale.h>
-#include <stdint.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
#include "rrd_hw.h"
#include "rrd_rpncalc.h"
*/
#include <sys/timeb.h>
-#ifndef __MINGW32__
-struct timeval {
- time_t tv_sec; /* seconds */
- long tv_usec; /* microseconds */
-};
-#endif
-
struct __timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
return -1;
}
#else
+ if (NULL == (base_dir = strdup(pathname_copy))) {
+ free(pathname_copy);
+ return -1;
+ }
+
_splitpath(pathname_copy, NULL, base_dir, NULL, NULL);
#endif
if (0 != rrd_mkdir_p(base_dir, mode)) {
int orig_errno = errno;
free(pathname_copy);
-#ifndef _MSC_VER
free(base_dir);
-#endif
errno = orig_errno;
return -1;
}
free(pathname_copy);
-#ifndef _MSC_VER
free(base_dir);
-#endif
/* keep errno as set by mkdir() */
#ifdef _MSC_VER
TOP = .\r
RRD_LIB_NAME=librrd-4\r
+ARCH_PATH_X86=contrib\r
+ARCH_PATH_X64=contrib-x64\r
+\r
\r
!ifndef USE_64BIT\r
LD_FLAGS=/RELEASE /MACHINE:X86\r
-\r
-CPPFLAGS = /TP /EHsc /O2 /arch:SSE2 /Zi /Fd$(TOP)/win32/vc.pdb \\r
- /I $(TOP)/win32 /I $(TOP)/src \\r
- /I E:\var\vcs\git\osb\windows-x86-msvcrt\include \\r
- /I E:\var\vcs\git\osb\windows-x86-msvcrt\include\cairo \\r
- /I E:\var\vcs\git\osb\windows-x86-msvcrt\include\pango-1.0 \\r
- /I E:\var\vcs\git\osb\windows-x86-msvcrt\include\glib-2.0 \\r
- /I E:\var\vcs\git\osb\windows-x86-msvcrt\include\libxml2\r
-\r
-THIRD_PARTY_LIB = /LIBPATH:E:\var\vcs\git\osb\windows-x86-msvcrt\lib \\r
- libpng.lib libxml2-2.lib \\r
- libglib-2.lib libgobject-2.lib \\r
- libpango-1.lib libpangocairo-1.lib libcairo-2.lib\r
-\r
+ARCH_PATH=$(ARCH_PATH_X86)\r
+CPPFLAGS = /arch:SSE2\r
!else\r
LD_FLAGS=/RELEASE /MACHINE:X64\r
+ARCH_PATH=$(ARCH_PATH_X64)\r
+!endif\r
\r
-CPPFLAGS = /TP /EHsc /O2 /Zi /Fd$(TOP)/win32/vc.pdb \\r
+CPPFLAGS = $(CCPFLAGS) /TP /EHsc /O2 /Zi /Fd$(TOP)/win32/vc.pdb \\r
/I $(TOP)/win32 /I $(TOP)/src \\r
- /I E:\var\vcs\git\osb\windows-x64-msvcrt\include \\r
- /I E:\var\vcs\git\osb\windows-x64-msvcrt\include\cairo \\r
- /I E:\var\vcs\git\osb\windows-x64-msvcrt\include\pango-1.0 \\r
- /I E:\var\vcs\git\osb\windows-x64-msvcrt\include\glib-2.0 \\r
- /I E:\var\vcs\git\osb\windows-x64-msvcrt\include\libxml2\r
+ /I $(ARCH_PATH)\include \\r
+ /I $(ARCH_PATH)\include\cairo \\r
+ /I $(ARCH_PATH)\include\pango-1.0 \\r
+ /I $(ARCH_PATH)\include\glib-2.0 \\r
+ /I $(ARCH_PATH)\lib\glib-2.0\include \\r
+ /I $(ARCH_PATH)\include\libxml2\r
\r
-THIRD_PARTY_LIB = /LIBPATH:E:\var\vcs\git\osb\windows-x64-msvcrt\lib \\r
- libpng.lib libxml2-2.lib \\r
- libglib-2.lib libgobject-2.lib \\r
- libpango-1.lib libpangocairo-1.lib libcairo-2.lib\r
-!endif\r
+THIRD_PARTY_LIB = /LIBPATH:$(ARCH_PATH)\lib \\r
+ libpng.lib libxml2.lib \\r
+ glib-2.0.lib gobject-2.0.lib \\r
+ pango-1.0.lib pangocairo-1.0.lib cairo.lib \\r
+ Ws2_32.lib\r
\r
RRD_LIB_OBJ_LIST = \\r
$(TOP)/src/hash_32.obj \\r
+ $(TOP)/src/mutex.obj \\r
$(TOP)/src/plbasename.obj \\r
$(TOP)/src/pngsize.obj \\r
+ $(TOP)/src/rrd_client.obj \\r
$(TOP)/src/rrd_create.obj \\r
$(TOP)/src/rrd_diff.obj \\r
$(TOP)/src/rrd_dump.obj \\r
1) See build-rrdtool.dot (build-rrdtool.svg or build-rrdtool.pdf) for build\r
dependency.\r
\r
-2) If you do not want to build the build-dependencies, you can download these\r
- software from the following address:\r
+2) If you do not want to build the build-dependencies, you can download prebuilt\r
+ versions from the following address:\r
\r
+ 32bit dependencies should then be extracted into the contrib directory:\r
http://ftp.gnome.org/pub/gnome/binaries/win32/\r
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/\r
\r
+ 64bit dependencies should then be extracted into the contrib-x64 directory:\r
http://ftp.gnome.org/pub/gnome/binaries/win64/\r
http://ftp.gnome.org/pub/gnome/binaries/win64/dependencies/\r
\r
-3) Adjust the include path, library path, and library names which in the\r
+\r
+3) If you don't already have stdint.h for your system you can download it\r
+ from the following address:\r
+ http://msinttypes.googlecode.com/svn/trunk/stdint.h\r
+\r
+4) Adjust the include path, library path, and library names which in the\r
Makefile.msc, to correspond with your local path or names.\r
\r
-4) Run 'nmake -f win32\Makefile.msc' for 32 bit Windows target,\r
+5) Run 'nmake -f win32\Makefile.msc' for 32 bit Windows target,\r
Run 'nmake -f win32\Makefile.msc USE_64BIT=1' for 64 bit Windows target.\r
Run 'nmake -f win32\Makefile.msc clean' to remove all generated files.\r
\r
-5) librrd-4.dll, librrd-4.lib, rrdtool.exe, rrdupdate.exe, rrdcgi.exe, and\r
+6) librrd-4.dll, librrd-4.lib, rrdtool.exe, rrdupdate.exe, rrdcgi.exe, and\r
these corresponding pdb files will be located in the win32 directory.\r
\r
-6) To install, copy these files which you required to their permanent location.\r
+7) To install, copy these files which you required to their permanent location.\r
\r
-7) To build the binding module. Follow the instructions in the README file which\r
+8) To build the binding module. Follow the instructions in the README file which\r
under the subdirectory of 'binding/'.\r
Linux x64 gcc, Windows x64 gcc, Visual C++ 2005 or later
*/
-/* The size of `time_t', as computed by sizeof. */
-#define SIZEOF_TIME_T 8 /* Visual C++ 2005 or later */
+/*
+ * The size of `time_t', as computed by sizeof.
+ * VS2005 and later dafault size for time_t is 64-bit, unless
+ * _USE_32BIT_TIME_T has been defined to use a 32-bit time_t.
+ */
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+# ifndef _USE_32BIT_TIME_T
+# define SIZEOF_TIME_T 8
+# else
+# define SIZEOF_TIME_T 4
+# endif
+#else
+# ifdef _WIN64
+# define SIZEOF_TIME_T 8
+# else
+# define SIZEOF_TIME_T 4
+# endif
+#endif
/* Define to 1 if you have the `chdir' function. */
#define HAVE_CHDIR 1
/* Define to 1 if you have the `tzset' function. */
#define HAVE_TZSET 1
+/* Misc Missing Windows defines */
+#define PATH_MAX 1024
+
+/*
+ * Windows Sockets errors redefined as regular Berkeley error constants.
+ */
+#define ENOBUFS WSAENOBUFS
+#define ENOTCONN WSAENOTCONN
+
#include <ctype.h>
#include <direct.h>
#include <float.h>
#include <math.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <WinSock.h>
#define isinf(a) (_fpclass(a) == _FPCLASS_NINF || _fpclass(a) == _FPCLASS_PINF)
#define isnan _isnan
#define finite _finite
#define snprintf _snprintf
#define rrd_realloc(a,b) ( (a) == NULL ? malloc( (b) ) : realloc( (a) , (b) ))
+#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
+#define strcasecmp _stricmp
+#define strcasencmp _strnicmp
+#pragma warning(disable: 4244)
__inline int round(double a){ return (int) (a + 0.5); }
#endif