1 /*****************************************************************************
2 * RRDtool 1.3.1 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
5 *****************************************************************************
6 * Initial version by Russ Wright, @Home Network, 9/28/98
7 *****************************************************************************/
10 #include "rrd_client.h"
16 char *opt_daemon = NULL;
19 opterr = 0; /* initialize getopt */
24 static struct option long_options[] = {
25 {"daemon", required_argument, 0, 'd'},
29 opt = getopt_long(argc, argv, "d:", long_options, &option_index);
36 if (opt_daemon != NULL)
38 opt_daemon = strdup (optarg);
39 if (opt_daemon == NULL)
41 rrd_set_error ("strdup failed.");
47 rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
54 if ((argc - optind) != 1) {
55 rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
60 if (opt_daemon == NULL)
64 temp = getenv (ENV_RRDCACHED_ADDRESS);
67 opt_daemon = strdup (temp);
68 if (opt_daemon == NULL)
70 rrd_set_error("strdup failed.");
76 if (opt_daemon != NULL)
80 status = rrdc_connect (opt_daemon);
83 rrd_set_error ("rrdc_connect failed with status %i.", status);
87 status = rrdc_flush (argv[optind]);
90 rrd_set_error ("rrdc_flush (%s) failed with status %i.",
91 argv[optind], status);
96 } /* if (opt_daemon) */
98 return (rrd_last_r (argv[optind]));
102 const char *filename)
105 rrd_file_t *rrd_file;
109 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
110 if (rrd_file != NULL) {
111 lastup = rrd.live_head->last_up;