On Wed, 2017-04-12 at 10:31 +0800, Paul Wise wrote: > I've attached a patch which renames the old RRD file > and creates a new one. Could we add it and restore sensord?
Attached a better version of the patch with two fixes: * No memory leak * Updates the new RRD after creation -- bye, pabs https://wiki.debian.org/PaulWise
--- a/prog/sensord/rrd.c
+++ b/prog/sensord/rrd.c
@@ -456,8 +456,34 @@
"sensord", sensord_args.rrdFile, rrdBuff, NULL
};
if ((ret = rrd_update(3, (char **) /* WEAK */ argv))) {
+ /* Cope with incompatible RRD files by creating new
+ ones and saving a backup of the old RRD files. */
+ const char *format = "%s.old";
+ size_t len = strlen(format) - 2 + strlen(sensord_args.rrdFile) + 1;
+ char *backup = (char*)malloc(len);
sensorLog(LOG_ERR, "Error updating RRD file: %s: %s",
sensord_args.rrdFile, rrd_get_error());
+ if (backup == NULL)
+ goto cleanup;
+ if (snprintf(backup, len, format, sensord_args.rrdFile) >= len)
+ goto cleanup;
+ if (rename(sensord_args.rrdFile, backup) != 0)
+ goto cleanup;
+ sensorLog(LOG_ERR, "Incompatible RRD file renamed from %s to %s",
+ sensord_args.rrdFile, backup);
+ ret = rrdInit();
+ if (!ret) {
+ sensorLog(LOG_ERR, "New RRD file created at %s",
+ sensord_args.rrdFile);
+ ret = rrd_update(3, (char **) /* WEAK */ argv);
+ } else {
+ rename(backup, sensord_args.rrdFile);
+ }
+ cleanup:
+ if (backup != NULL)
+ free(backup);
+ if (ret)
+ return ret;
}
}
sensorLog(LOG_DEBUG, "sensor rrd updated");
signature.asc
Description: This is a digitally signed message part

