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

[Cluster-devel] cluster/group daemon/main.c lib/libgroup.c too ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rpeterso sourceware org	2006-10-21 17:15:12

Modified files:
	group/daemon   : main.c 
	group/lib      : libgroup.c 
	group/tool     : main.c 

Log message:
	This is the fix for Bugzilla Bug 210344: group_tool does not
	handle short reads.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/daemon/main.c.diff?cvsroot=cluster&r1=1.49&r2=1.50
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/lib/libgroup.c.diff?cvsroot=cluster&r1=1.22&r2=1.23
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/tool/main.c.diff?cvsroot=cluster&r1=1.20&r2=1.21

--- cluster/group/daemon/main.c	2006/10/20 15:42:44	1.49
+++ cluster/group/daemon/main.c	2006/10/21 17:15:12	1.50
@@ -490,30 +490,24 @@
 {
 	group_t *g;
 	group_data_t *data;
-	int i, rv, len, count = 0, max = atoi(argv[1]);
+	int rv, count = 0, max = atoi(argv[1]);
 
-	list_for_each_entry(g, &gd_groups, list)
-		count++;
-	if (count > max)
-		count = max;
-	/* if no groups, send back one empty data struct */
-	if (!count)
-		count = 1;
-
-	len = count * sizeof(group_data_t);
-	data = malloc(len);
-	memset(data, 0, len);
-
-	i = 0;
+	data = malloc(sizeof(group_data_t));
+	count = 0;
 	list_for_each_entry(g, &gd_groups, list) {
-		copy_group_data(g, &data[i]);
-		i++;
+		copy_group_data(g, data);
+		rv = do_write(client[ci].fd, data, sizeof(group_data_t));
+		if (rv < 0) {
+			log_print("do_get_groups write error");
+			break;
+		}
+		count++;
+		if (count >= max)
+			break;
 	}
-
-	rv = do_write(client[ci].fd, data, len);
-	if (rv < 0)
-		log_print("do_get_groups write error");
-
+	/* Now write an empty one indicating there aren't anymore: */
+	memset(data, 0, sizeof(group_data_t));
+	rv = do_write(client[ci].fd, data, sizeof(group_data_t));
 	free(data);
 	return 0;
 }
--- cluster/group/lib/libgroup.c	2006/10/13 17:15:26	1.22
+++ cluster/group/lib/libgroup.c	2006/10/21 17:15:12	1.23
@@ -446,11 +446,11 @@
 	return rv;
 }
 
-int group_get_groups(int max, int *count, group_data_t *data)
+int group_get_groups(int max, int *count, group_data_t  *data)
 {
 	char buf[GROUPD_MSGLEN];
 	group_data_t empty;
-	int fd, rv, maxlen;
+	int fd, rv;
 
 	fd = connect_groupd();
 	if (fd < 0)
@@ -461,21 +461,20 @@
 	snprintf(buf, sizeof(buf), "get_groups %d", max);
 
 	rv = do_write(fd, &buf, GROUPD_MSGLEN);
-	if (rv < 0)
-		goto out;
-
-	maxlen = max * sizeof(group_data_t);
-
-	rv = read(fd, data, maxlen);
-	if (rv > 0) {
-		/* a blank data struct is returned when there are none */
-		if (rv == sizeof(empty) && !memcmp(data, &empty, rv))
-			*count = 0;
-		else
-			*count = rv / sizeof(group_data_t);
-		rv = 0;
+	*count = 0;
+	if (!rv) {
+		while (1) {
+			rv = read(fd, &data[*count], sizeof(group_data_t));
+			/* a blank data struct is returned when there are none */
+			if (rv <= 0 || (rv == sizeof(group_data_t) &&
+							!memcmp(&data[*count], &empty, rv))) {
+				rv = 0;
+				break;
+			}
+			else
+				(*count)++;
+		}
 	}
- out:
 	close(fd);
 	return rv;
 }
--- cluster/group/tool/main.c	2006/08/14 19:38:20	1.20
+++ cluster/group/tool/main.c	2006/10/21 17:15:12	1.21
@@ -247,6 +247,10 @@
 	} else
 		rv = group_get_groups(MAX_GROUPS, &count, data);
 
+	if (rv < 0) {
+		fprintf(stderr,"Unable to connect to groupd.  Is it running?\n");
+		return rv;
+	}
 	for (i = 0; i < count; i++) {
 		len = strlen(data[i].name);
 		if (len > max_name)


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