浏览代码

Don't assert when ring id file is less then 8 bytes

If the ring id file for the processor is less then 8 bytes, totemsrp would
assert.  Our speculation is that this condition happens during a fencing
operation or local filesystem corruption.

With this patch, Corosync will create fresh ring id file data when the
incorrect number of bytes are read from the ring id.

Amend to use sizeof the strerror string length and PATH_MAX for the path length.

Signed-off-by: Steven Dake <sdake@redhat.com>
Reviewed-by: Angus Salkeld <asalkeld@redhat.com>
Steven Dake 15 年之前
父节点
当前提交
7471c88346
共有 1 个文件被更改,包括 24 次插入17 次删除
  1. 24 17
      exec/totemsrp.c

+ 24 - 17
exec/totemsrp.c

@@ -3094,35 +3094,42 @@ static void memb_ring_id_create_or_load (
 	struct memb_ring_id *memb_ring_id)
 {
 	int fd;
-	int res;
-	char filename[256];
-	char error_str[100];
+	int res = 0;
+	char filename[PATH_MAX];
+	char error_str[256];
 
 	snprintf (filename, sizeof(filename), "%s/ringid_%s",
 		rundir, totemip_print (&instance->my_id.addr[0]));
 	fd = open (filename, O_RDONLY, 0700);
-	if (fd > 0) {
-		res = read (fd, &memb_ring_id->seq, sizeof (unsigned long long));
-		assert (res == sizeof (unsigned long long));
+	/*
+	 * If file can be opened and read, read the ring id
+	 */
+	if (fd != -1) {
+		res = read (fd, &memb_ring_id->seq, sizeof (uint64_t));
 		close (fd);
-	} else
-	if (fd == -1 && errno == ENOENT) {
+	}
+	/*
+ 	 * If file could not be opened or read, create a new ring id
+ 	 */
+	if ((fd == -1) || (res != sizeof (uint64_t))) {
 		memb_ring_id->seq = 0;
 		umask(0);
 		fd = open (filename, O_CREAT|O_RDWR, 0700);
-		if (fd >= 0) {
-			res = write (fd, &memb_ring_id->seq, sizeof (unsigned long long));
-			assert (res == sizeof (unsigned long long));
+		if (fd != -1) {
+			res = write (fd, &memb_ring_id->seq, sizeof (uint64_t));
 			close (fd);
+			if (res == -1) {
+				strerror_r (errno, error_str, sizeof (error_str));
+				log_printf (instance->totemsrp_log_level_warning,
+					"Couldn't write ringid file '%s' %s\n",
+					filename, error_str);
+			}
 		} else {
-			strerror_r (errno, error_str, 100);
+			strerror_r (errno, error_str, sizeof (error_str));
 			log_printf (instance->totemsrp_log_level_warning,
-				"Couldn't create %s %s\n", filename, error_str);
+				"Couldn't create ringid file '%s' %s\n",
+				filename, error_str);
 		}
-	} else {
-		strerror_r (errno, error_str, 100);
-		log_printf (instance->totemsrp_log_level_warning,
-			"Couldn't open %s %s\n", filename, error_str);
 	}
 
 	totemip_copy(&memb_ring_id->rep, &instance->my_id.addr[0]);