}
}
-static int send_values_to_daemon (const char *addr, const char *file,
- int values_num, const char * const *values, int silent)
-{
- int status;
-
- status = rrdc_connect ((addr != NULL) ? addr : RRDD_SOCK_PATH);
- if (status != 0)
- {
- if (!silent)
- {
- rrd_set_error("Unable to connect to daemon: %s",
- (status < 0)
- ? "Internal error"
- : rrd_strerror (status));
- }
- return (status);
- }
-
- status = rrdc_update (file, values_num, values);
- if (status != 0)
- {
- if (!silent)
- {
- rrd_set_error("Failed sending the values to the daemon: %s",
- (status < 0)
- ? "Internal error"
- : rrd_strerror (status));
- }
- rrdc_disconnect ();
- return (status);
- }
-
- rrdc_disconnect ();
- return (0);
-} /* int send_values_to_daemon */
-
#define IFDNAN(X,Y) (isnan(X) ? (Y) : (X));
rrd_info_t *rrd_update_v(
int opt;
char *tmplt = NULL;
int rc = -1;
- /* force_cache: 0 = default; -1 = force no cache; 1 = force cache */
- int force_cache = 0;
- char *daemon_address = NULL;
+ char *daemon = NULL;
optind = 0;
opterr = 0; /* initialize getopt */
tmplt = strdup(optarg);
break;
- case 'c':
- if (optarg != NULL)
- {
- if (strcmp ("no", optarg) == 0)
- force_cache = -1;
- else if (strcmp ("yes", optarg) == 0)
- force_cache = 1;
- else
- {
- rrd_set_error ("option 'cache' must be "
- "either 'yes' or 'no'.");
- goto out;
- }
- }
- else
- force_cache = 1;
- break;
-
- case 'n':
- force_cache = -1;
- break;
-
case 'd':
- if (daemon_address != NULL)
- free (daemon_address);
- daemon_address = strdup (optarg);
- if (daemon_address == NULL)
+ if (daemon != NULL)
+ free (daemon);
+ daemon = strdup (optarg);
+ if (daemon == NULL)
{
rrd_set_error("strdup failed.");
goto out;
goto out;
}
- if ((tmplt != NULL) && (force_cache > 0))
+ if ((tmplt != NULL) && (daemon != NULL))
{
rrd_set_error("The caching daemon cannot be used together with "
"templates yet.");
goto out;
}
- if ((tmplt == NULL) && (force_cache >= 0))
+ if (daemon != NULL)
{
int status;
- status = send_values_to_daemon (daemon_address,
- /* file = */ argv[optind],
- /* values_num = */ argc - optind - 1,
- /* values = */ (void *) (argv + optind + 1),
- /* silent = */ (force_cache > 0) ? 0 : 1);
- if ((status == 0) || (force_cache > 0))
+ status = rrdc_connect (daemon);
+ if (status != 0)
+ {
+ rrd_set_error("Unable to connect to daemon: %s",
+ (status < 0)
+ ? "Internal error"
+ : rrd_strerror (status));
goto out;
- } /* if ((tmplt != NULL) && (force_cache >= 0)) */
+ }
+
+ status = rrdc_update (/* file = */ argv[optind],
+ /* values_num = */ argc - optind - 1,
+ /* values = */ (void *) (argv + optind + 1));
+ if (status != 0)
+ {
+ rrd_set_error("Failed sending the values to the daemon: %s",
+ (status < 0)
+ ? "Internal error"
+ : rrd_strerror (status));
+ }
+
+ rrdc_disconnect ();
+ goto out;
+ } /* if (daemon != NULL) */
rc = rrd_update_r(argv[optind], tmplt,
argc - optind - 1, (const char **) (argv + optind + 1));
free(tmplt);
tmplt = NULL;
}
- if (daemon_address != NULL)
+ if (daemon != NULL)
{
- free (daemon_address);
- daemon_address = NULL;
+ free (daemon);
+ daemon = NULL;
}
return rc;
}