X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_last.c;h=7fb3cb884344f8c76119d9b7b7c860b092afbcc2;hp=e2ea29a93849d51b4ebb44ee16977dab95fdf48b;hb=e5b05bec82bbff5db8add4e58dd6f0fcf2670291;hpb=e1c12d5c14b4a716ea999204cedb13e98466ff15 diff --git a/src/rrd_last.c b/src/rrd_last.c index e2ea29a..7fb3cb8 100644 --- a/src/rrd_last.c +++ b/src/rrd_last.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3rc3 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010 ***************************************************************************** * rrd_last.c ***************************************************************************** @@ -7,19 +7,78 @@ *****************************************************************************/ #include "rrd_tool.h" +#include "rrd_client.h" time_t rrd_last( int argc, char **argv) { - if (argc < 2) { - rrd_set_error("please specify an rrd"); + char *opt_daemon = NULL; + int status; + time_t lastupdate; + int flushfirst = 1; + + optind = 0; + opterr = 0; /* initialize getopt */ + + while (42) { + int opt; + int option_index = 0; + static struct option long_options[] = { + {"daemon", required_argument, 0, 'd'}, + {"noflush", no_argument, 0, 'F'}, + {0, 0, 0, 0} + }; + + opt = getopt_long(argc, argv, "d:F", long_options, &option_index); + + if (opt == EOF) + break; + + switch (opt) { + case 'd': + if (opt_daemon != NULL) + free (opt_daemon); + opt_daemon = strdup (optarg); + if (opt_daemon == NULL) + { + rrd_set_error ("strdup failed."); + return (-1); + } + break; + + case 'F': + flushfirst = 0; + break; + + default: + rrd_set_error ("Usage: rrdtool %s [--daemon [--noflush]] ", + argv[0]); + return (-1); + break; + } + } /* while (42) */ + + if ((argc - optind) != 1) { + rrd_set_error ("Usage: rrdtool %s [--daemon [--noflush]] ", + argv[0]); return (-1); } - return (rrd_last_r(argv[1])); -} + if(flushfirst) { + status = rrdc_flush_if_daemon(opt_daemon, argv[optind]); + if (status) return (-1); + } + rrdc_connect (opt_daemon); + if (rrdc_is_connected (opt_daemon)) + lastupdate = rrdc_last (argv[optind]); + + else + lastupdate = rrd_last_r(argv[optind]); + + return (lastupdate); +} time_t rrd_last_r( const char *filename) @@ -29,6 +88,7 @@ time_t rrd_last_r( rrd_t rrd; + rrd_init(&rrd); rrd_file = rrd_open(filename, &rrd, RRD_READONLY); if (rrd_file != NULL) { lastup = rrd.live_head->last_up;