+int rrd_lastupdate (int argc, char **argv)
+{
+ time_t last_update;
+ char **ds_names;
+ char **last_ds;
+ unsigned long ds_count, i;
+ int status;
+
+ char *opt_daemon = NULL;
+
+ 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);
+ }
+
+ status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
+ if (opt_daemon) free (opt_daemon);
+ if (status) return (-1);
+
+ status = rrd_lastupdate_r (argv[optind],
+ &last_update, &ds_count, &ds_names, &last_ds);
+ if (status != 0)
+ return (status);
+
+ for (i = 0; i < ds_count; i++)
+ printf(" %s", ds_names[i]);
+ printf ("\n\n");
+
+ printf ("%10lu:", last_update);
+ for (i = 0; i < ds_count; i++) {
+ printf(" %s", last_ds[i]);
+ free(last_ds[i]);
+ free(ds_names[i]);
+ }
+ printf("\n");
+
+ free(last_ds);
+ free(ds_names);
+
+ return (0);
+} /* int rrd_lastupdate */
+
+int rrd_lastupdate_r(const char *filename,
+ time_t *ret_last_update,
+ unsigned long *ret_ds_count,
+ char ***ret_ds_names,
+ char ***ret_last_ds)
+{
+ unsigned long i = 0;
+ rrd_t rrd;
+ rrd_file_t *rrd_file;
+
+ rrd_init(&rrd);
+ rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
+ if (rrd_file == NULL) {
+ rrd_free(&rrd);
+ return (-1);