From: octo Date: Tue, 21 Mar 2006 12:42:48 +0000 (+0000) Subject: Implemented function to subtract two `struct timeval' and get the difference in a... X-Git-Tag: liboping-0.1.0~143^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fa97a59b9724584da6f3cb89a73fb5c7e23fc0f5;p=collectd.git Implemented function to subtract two `struct timeval' and get the difference in a `struct timespec' --- diff --git a/src/common.c b/src/common.c index 3c416fc2..72cc5589 100644 --- a/src/common.c +++ b/src/common.c @@ -34,6 +34,7 @@ extern kstat_ctl_t *kc; #endif #ifdef HAVE_LIBRRD +#if 0 static char *rra_def[] = { "RRA:AVERAGE:0.0:1:1500", @@ -51,6 +52,7 @@ static char *rra_def[] = NULL }; static int rra_num = 12; +#endif static int rra_timespans[] = { @@ -208,6 +210,29 @@ int escape_slashes (char *buf, int buf_len) return (0); } +int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret) +{ + if ((tv0 == NULL) || (tv1 == NULL) || (ret == NULL)) + return (-2); + + if ((tv0->tv_sec < tv1->tv_sec) + || ((tv0->tv_sec == tv1->tv_sec) && (tv0->tv_usec < tv1->tv_usec))) + return (-1); + + ret->tv_sec = tv0->tv_sec - tv1->tv_sec; + ret->tv_nsec = 1000 * ((long) (tv0->tv_usec - tv1->tv_usec)); + + if (ret->tv_nsec < 0) + { + assert (ret->tv_sec > 0); + + ret->tv_nsec += 1000000000; + ret->tv_sec -= 1; + } + + return (0); +} + #ifdef HAVE_LIBRRD int check_create_dir (const char *file_orig) { @@ -398,13 +423,19 @@ int rrd_create_file (char *filename, char **ds_def, int ds_num) { char **argv; int argc; + char **rra_def; + int rra_num; int i, j; int status = 0; if (check_create_dir (filename)) return (-1); - rra_get (&argv); /* FIXME */ + if ((rra_num = rra_get (&rra_def)) < 1) + { + syslog (LOG_ERR, "rra_create failed: Could not calculate RRAs"); + return (-1); + } argc = ds_num + rra_num + 4; diff --git a/src/common.h b/src/common.h index 59984b18..fafce4a8 100644 --- a/src/common.h +++ b/src/common.h @@ -103,6 +103,9 @@ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const */ int escape_slashes (char *buf, int buf_len); +/* FIXME: `timeval_sub_timespec' needs a description */ +int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret); + int rrd_update_file (char *host, char *file, char *values, char **ds_def, int ds_num);