From: Florian Forster Date: Fri, 7 Nov 2008 18:49:52 +0000 (+0100) Subject: src/utils_rrdcreate.c: srrd_create: Copy the `filename' argument. X-Git-Tag: collectd-4.6.0~164 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=60a77a6f3855f181e723aa3f4f645ea480ddd359;p=collectd.git src/utils_rrdcreate.c: srrd_create: Copy the `filename' argument. Some versions of librrd, for example the one in Debian Etch, don't have the `const' qualifier for the first (filename) argument for `rrd_create_r'. So we'll copy the argument first. This sucks big time, but is the only reasonable way to get around this. --- diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index 99feda25..8ff025bd 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -253,11 +253,26 @@ static int srrd_create (const char *filename, /* {{{ */ int argc, const char **argv) { int status; + char *filename_copy; + + if ((filename == NULL) || (argv == NULL)) + return (-EINVAL); + + /* Some versions of librrd don't have the `const' qualifier for the first + * argument, so we have to copy the pointer here to avoid warnings. It sucks, + * but what else can we do? :( -octo */ + filename_copy = strdup (filename); + if (filename_copy == NULL) + { + ERROR ("srrd_create: strdup failed."); + return (-ENOMEM); + } optind = 0; /* bug in librrd? */ rrd_clear_error (); - status = rrd_create_r (filename, pdp_step, last_up, argc, (void *) argv); + status = rrd_create_r (filename_copy, pdp_step, last_up, + argc, (void *) argv); if (status != 0) { @@ -265,6 +280,8 @@ static int srrd_create (const char *filename, /* {{{ */ filename, rrd_get_error ()); } + sfree (filename_copy); + return (status); } /* }}} int srrd_create */ /* #endif HAVE_THREADSAFE_LIBRRD */