[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/group/dlm_controld action.c group.c main.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	teigland sourceware org	2006-08-31 18:17:00

Modified files:
	group/dlm_controld: action.c group.c main.c 

Log message:
	- break from snprintf loop when buffer is filled
	- handle some odd error cases like EINTR
	- handle short writes

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/dlm_controld/action.c.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/dlm_controld/group.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/dlm_controld/main.c.diff?cvsroot=cluster&r1=1.4&r2=1.5

--- cluster/group/dlm_controld/action.c	2006/07/24 18:50:01	1.5
+++ cluster/group/dlm_controld/action.c	2006/08/31 18:17:00	1.6
@@ -46,10 +46,31 @@
 #define COMMS_DIR     "/sys/kernel/config/dlm/cluster/comms"
 
 
+static int do_write(int fd, void *buf, size_t count)
+{
+	int rv, off = 0;
+
+ retry:
+	rv = write(fd, buf + off, count);
+	if (rv == -1 && errno == EINTR)
+		goto retry;
+	if (rv < 0) {
+		log_error("write errno %d", errno);
+		return rv;
+	}
+
+	if (rv != count) {
+		count -= rv;
+		off += rv;
+		goto retry;
+	}
+	return 0;
+}
+
 static int do_sysfs(char *name, char *file, char *val)
 {
 	char fname[512];
-	int rv, fd, len;
+	int rv, fd;
 
 	sprintf(fname, "%s/%s/%s", DLM_SYSFS_DIR, name, file);
 
@@ -61,14 +82,7 @@
 
 	log_debug("write \"%s\" to \"%s\"", val, fname);
 
-	len = strlen(val) + 1;
-	rv = write(fd, val, len);
-	if (rv != len) {
-		log_error("write %d error %d %d", len, rv, errno);
-		rv = -1;
-	} else
-		rv = 0;
-
+	rv = do_write(fd, val, strlen(val) + 1);
 	close(fd);
 	return rv;
 }
@@ -314,7 +328,7 @@
 		memset(buf, 0, 32);
 		snprintf(buf, 32, "%d", id);
 
-		rv = write(fd, buf, strlen(buf));
+		rv = do_write(fd, buf, strlen(buf));
 		if (rv < 0) {
 			log_error("%s: write failed: %d, %s", path, errno, buf);
 			close(fd);
@@ -344,7 +358,7 @@
 		memset(buf, 0, 32);
 		snprintf(buf, 32, "%d", w);
 
-		rv = write(fd, buf, strlen(buf));
+		rv = do_write(fd, buf, strlen(buf));
 		if (rv < 0) {
 			log_error("%s: write failed: %d, %s", path, errno, buf);
 			close(fd);
@@ -360,6 +374,7 @@
 	return rv;
 }
 
+#if 0
 char *str_ip(char *addr)
 {
 	static char ip[256];
@@ -368,6 +383,24 @@
 	inet_ntop(AF_INET, &sin->sin_addr, ip, 256);
 	return ip;
 }
+#endif
+
+char *str_ip(char *addr)
+{
+	static char str_ip_buf[INET6_ADDRSTRLEN];
+	struct sockaddr_storage *ss = (struct sockaddr_storage *)addr;
+	struct sockaddr_in *sin = (struct sockaddr_in *)addr;
+	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
+	void *saddr;
+
+	if (ss->ss_family == AF_INET6)
+		saddr = &sin6->sin6_addr;
+	else
+		saddr = &sin->sin_addr;
+
+	inet_ntop(ss->ss_family, saddr, str_ip_buf, sizeof(str_ip_buf));
+	return str_ip_buf;
+}
 
 /* record the nodeids that are currently listed under
    config/dlm/cluster/comms/ so that we can remove all of them */
@@ -539,7 +572,7 @@
 	memset(buf, 0, sizeof(buf));
 	snprintf(buf, 32, "%d", nodeid);
 
-	rv = write(fd, buf, strlen(buf));
+	rv = do_write(fd, buf, strlen(buf));
 	if (rv < 0) {
 		log_error("%s: write failed: %d, %s", path, errno, buf);
 		close(fd);
@@ -563,8 +596,8 @@
 		return -1;
 	}
 
-	rv = write(fd, padded_addr, sizeof(struct sockaddr_storage));
-	if (rv != sizeof(struct sockaddr_storage)) {
+	rv = do_write(fd, padded_addr, sizeof(struct sockaddr_storage));
+	if (rv < 0) {
 		log_error("%s: write failed: %d %d", path, errno, rv);
 		close(fd);
 		return -1;
@@ -587,7 +620,7 @@
 		return -1;
 	}
 
-	rv = write(fd, "1", strlen("1"));
+	rv = do_write(fd, "1", strlen("1"));
 	if (rv < 0) {
 		log_error("%s: write failed: %d", path, errno);
 		close(fd);
--- cluster/group/dlm_controld/group.c	2006/06/09 20:59:57	1.1
+++ cluster/group/dlm_controld/group.c	2006/08/31 18:17:00	1.2
@@ -85,14 +85,22 @@
 char *str_members(void)
 {
 	static char str_members_buf[MAXLINE];
-	int i, len = 0;
+	int i, ret, pos = 0, len = MAXLINE;
 
 	memset(str_members_buf, 0, MAXLINE);
 
 	for (i = 0; i < cb_member_count; i++) {
-		if (i != 0)
-			len += sprintf(str_members_buf+len, " ");
-		len += sprintf(str_members_buf+len, "%d", cb_members[i]);
+		if (i != 0) {
+			ret = snprintf(str_members_buf + pos, len - pos, " ");
+			if (ret >= len - pos)
+				break;
+			pos += ret;
+		}
+		ret = snprintf(str_members_buf + pos, len - pos, "%d",
+			       cb_members[i]);
+		if (ret >= len - pos)
+			break;
+		pos += ret;
 	}
 	return str_members_buf;
 }
--- cluster/group/dlm_controld/main.c	2006/08/15 17:17:46	1.4
+++ cluster/group/dlm_controld/main.c	2006/08/31 18:17:00	1.5
@@ -29,10 +29,11 @@
 	struct lockspace *ls;
 
 	ls = malloc(sizeof(*ls));
+	if (!ls)
+		goto out;
 	memset(ls, 0, sizeof(*ls));
-
 	strncpy(ls->name, name, MAXNAME);
-
+ out:
 	return ls;
 }
 
@@ -112,7 +113,12 @@
 	memset(buf, 0, sizeof(buf));
 	memset(argv, 0, sizeof(char *) * MAXARGS);
 
+ retry_recv:
 	rv = recv(uevent_fd, &buf, sizeof(buf), 0);
+	if (rv == -1 && rv == EINTR)
+		goto retry_recv;
+	if (rv == -1 && rv == EAGAIN)
+		return 0;
 	if (rv < 0) {
 		log_error("uevent recv error %d errno %d", rv, errno);
 		goto out;
@@ -226,8 +232,10 @@
 
 	for (;;) {
 		rv = poll(pollfd, maxi + 1, -1);
+		if (rv == -1 && errno == EINTR)
+			continue;
 		if (rv < 0) {
-			log_error("poll");
+			log_error("poll errno %d", errno);
 			goto out;
 		}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]