- rc = rrd_update_r(argv[optind], tmplt,
- argc - optind - 1, (const char **) (argv + optind + 1));
+ { /* try to connect to rrdcached */
+ int status = rrdc_connect(opt_daemon);
+ if (status != 0) return status;
+ }
+
+ if ((tmplt != NULL) && rrdc_is_connected(opt_daemon))
+ {
+ rrd_set_error("The caching daemon cannot be used together with "
+ "templates yet.");
+ goto out;
+ }
+
+ if (! rrdc_is_connected(opt_daemon))
+ {
+ rc = rrd_update_r(argv[optind], tmplt,
+ argc - optind - 1, (const char **) (argv + optind + 1));
+ }
+ else /* we are connected */
+ {
+ rc = rrdc_update (argv[optind], /* file */
+ argc - optind - 1, /* values_num */
+ (const char *const *) (argv + optind + 1)); /* values */
+ if (rc > 0)
+ rrd_set_error("Failed sending the values to rrdcached: %s",
+ rrd_strerror (rc));
+ }
+