2 * RRDTool - src/rrd_flush.c
3 * Copyright (C) 2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
23 #include "rrd_client.h"
25 int rrd_cmd_flush (int argc, char **argv)
27 char *opt_daemon = NULL;
30 /* initialize getopt */
37 static struct option long_options[] =
39 {"daemon", required_argument, 0, 'd'},
43 opt = getopt_long(argc, argv, "d:", long_options, NULL);
51 if (opt_daemon != NULL)
53 opt_daemon = strdup (optarg);
54 if (opt_daemon == NULL)
56 rrd_set_error ("strdup failed.");
62 rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
68 if ((argc - optind) != 1)
70 rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>", argv[0]);
74 /* try to connect to rrdcached */
75 status = rrdc_connect(opt_daemon);
76 if (opt_daemon) free(opt_daemon);
77 if (status != 0) return status;
79 if (! rrdc_is_connected(opt_daemon))
81 rrd_set_error ("Daemon address unknown. Please use the \"--daemon\" "
82 "option to set an address on the command line or set the "
83 "\"%s\" environment variable.",
84 ENV_RRDCACHED_ADDRESS);
88 status = rrdc_flush(argv[optind]);
90 return ((status == 0) ? 0 : -1);
94 * vim: set sw=4 sts=4 et fdm=marker :