diff --git a/src/rrd_last.c b/src/rrd_last.c
index e0fad847c9ae06d98595e4f08e386ab5926ad9d1..90bcae7afc608997f5a1709f3ee066ae7fe2356e 100644 (file)
--- a/src/rrd_last.c
+++ b/src/rrd_last.c
/*****************************************************************************
/*****************************************************************************
- * RRDtool 1.2.1 Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
*****************************************************************************
* rrd_last.c
*****************************************************************************
*****************************************************************************
* rrd_last.c
*****************************************************************************
*****************************************************************************/
#include "rrd_tool.h"
*****************************************************************************/
#include "rrd_tool.h"
+#include "rrd_client.h"
-time_t
-rrd_last(int argc, char **argv)
+time_t rrd_last(
+ int argc,
+ char **argv)
{
{
- if(argc < 2){
- rrd_set_error("please specify an rrd");
- return(-1);
+ char *opt_daemon = NULL;
+ time_t lastupdate;
+
+ optind = 0;
+ opterr = 0; /* initialize getopt */
+
+ while (42) {
+ int opt;
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"daemon", required_argument, 0, 'd'},
+ {0, 0, 0, 0}
+ };
+
+ opt = getopt_long(argc, argv, "d:", 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;
+
+ default:
+ rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
+ argv[0]);
+ return (-1);
+ break;
+ }
+ } /* while (42) */
+
+ if ((argc - optind) != 1) {
+ rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
+ argv[0]);
+ return (-1);
}
}
- return( rrd_last_r(argv[1]) );
+ rrdc_connect (opt_daemon);
+ if (rrdc_is_connected (opt_daemon))
+ lastupdate = rrdc_last (argv[optind]);
+
+ else
+ lastupdate = rrd_last_r(argv[optind]);
+
+ if (opt_daemon) free(opt_daemon);
+ return (lastupdate);
}
}
-
-time_t
-rrd_last_r(const char *filename)
+time_t rrd_last_r(
+ const char *filename)
{
{
- FILE *in_file;
- time_t lastup;
+ time_t lastup = -1;
+ rrd_file_t *rrd_file;
- rrd_t rrd;
+ rrd_t rrd;
- if(rrd_open(filename, &in_file, &rrd, RRD_READONLY)==-1){
- return(-1);
+ rrd_init(&rrd);
+ rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
+ if (rrd_file != NULL) {
+ lastup = rrd.live_head->last_up;
+ rrd_close(rrd_file);
}
}
- lastup = rrd.live_head->last_up;
rrd_free(&rrd);
rrd_free(&rrd);
- fclose(in_file);
- return(lastup);
+ return (lastup);
}
}
-
-