Просмотр исходного кода

Merge trunk revision 2825:
r2825 | asalkeld | 2010-05-13 19:05:32 -0700 (Thu, 13 May 2010) | 2 lines

cov 10382: improve error handling around open()



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2868 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 15 лет назад
Родитель
Сommit
bc79412d20
1 измененных файлов с 8 добавлено и 8 удалено
  1. 8 8
      exec/totemsrp.c

+ 8 - 8
exec/totemsrp.c

@@ -3063,6 +3063,7 @@ static void memb_ring_id_create_or_load (
 	int fd;
 	int res;
 	char filename[256];
+	char error_str[100];
 
 	snprintf (filename, sizeof(filename), "%s/ringid_%s",
 		rundir, totemip_print (&instance->my_id.addr[0]));
@@ -3076,18 +3077,17 @@ static void memb_ring_id_create_or_load (
 		memb_ring_id->seq = 0;
 		umask(0);
 		fd = open (filename, O_CREAT|O_RDWR, 0700);
-		if (fd == -1) {
-			char error_str[100];
-			strerror_r(errno, error_str, 100);
+		if (fd >= 0) {
+			res = write (fd, &memb_ring_id->seq, sizeof (unsigned long long));
+			assert (res == sizeof (unsigned long long));
+			close (fd);
+		} else {
+			strerror_r (errno, error_str, 100);
 			log_printf (instance->totemsrp_log_level_warning,
 				"Couldn't create %s %s\n", filename, error_str);
 		}
-		res = write (fd, &memb_ring_id->seq, sizeof (unsigned long long));
-		assert (res == sizeof (unsigned long long));
-		close (fd);
 	} else {
-		char error_str[100];
-		strerror_r(errno, error_str, 100);
+		strerror_r (errno, error_str, 100);
 		log_printf (instance->totemsrp_log_level_warning,
 			"Couldn't open %s %s\n", filename, error_str);
 	}