Control: tags -1 + patch

On Wed, 2017-04-12 at 08:42 +0800, Paul Wise wrote:

> I'm going to try to write a patch to achieve this now.

I've attached a patch which renames the old RRD file
and creates a new one. Could we add it and restore sensord?

-- 
bye,
pabs

https://wiki.debian.org/PaulWise
--- a/prog/sensord/rrd.c
+++ b/prog/sensord/rrd.c
@@ -456,8 +456,31 @@
 			"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 error;
+			if (snprintf(backup, len, format, sensord_args.rrdFile) >= len)
+				goto error;
+			if (rename(sensord_args.rrdFile, backup) != 0)
+				goto error;
+			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);
+			} else {
+				rename(backup, sensord_args.rrdFile);
+				error:
+					free(backup);
+					return ret;
+			}
 		}
 	}
 	sensorLog(LOG_DEBUG, "sensor rrd updated");

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to