From: rpeterso@sourceware.org <rpeterso@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/group daemon/main.c lib/libgroup.c too ...
Date: 21 Oct 2006 17:15:13 -0000 [thread overview]
Message-ID: <20061021171513.22554.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: rpeterso at 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)
reply other threads:[~2006-10-21 17:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061021171513.22554.qmail@sourceware.org \
--to=rpeterso@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.