From: teigland@sourceware.org <teigland@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/group/lib libgroup.c
Date: 7 Sep 2006 19:24:09 -0000 [thread overview]
Message-ID: <20060907192409.13137.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: teigland at sourceware.org 2006-09-07 19:24:08
Modified files:
group/lib : libgroup.c
Log message:
handle short or interrupted reads/writes, an snprintf instead of sprintf,
strtoul instead of atoi, handle an ENOMEM
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/lib/libgroup.c.diff?cvsroot=cluster&r1=1.19&r2=1.20
--- cluster/group/lib/libgroup.c 2006/02/28 20:31:27 1.19
+++ cluster/group/lib/libgroup.c 2006/09/07 19:24:08 1.20
@@ -88,7 +88,7 @@
return rp;
}
-void get_nodeids(char *buf, int memb_count, int *nodeids)
+static void get_nodeids(char *buf, int memb_count, int *nodeids)
{
char *p;
int i, count = 0;
@@ -112,7 +112,7 @@
}
}
-int get_action(char *buf)
+static int get_action(char *buf)
{
char act[16];
int i;
@@ -151,15 +151,32 @@
{
int rv, off = 0;
- again:
+ retry:
rv = write(fd, buf + off, count);
+ if (rv == -1 && errno == EINTR)
+ goto retry;
if (rv < 0)
return rv;
if (rv != count) {
count -= rv;
off += rv;
- goto again;
+ goto retry;
+ }
+ return 0;
+}
+
+static int do_read(int fd, void *buf, size_t count)
+{
+ int rv, off = 0;
+
+ while (off < count) {
+ rv = read(fd, buf + off, count - off);
+ if (rv == 0)
+ return -1;
+ if (rv == -1 && errno == EINTR)
+ continue;
+ off += rv;
}
return 0;
}
@@ -231,7 +248,7 @@
return -EINVAL;
memset(buf, 0, sizeof(buf));
- rv = sprintf(buf, "send %s %d", name, len);
+ rv = snprintf(buf, sizeof(buf), "send %s %d", name, len);
memcpy(buf + rv + 1, data, len);
return do_write(h->fd, buf, GROUPD_MSGLEN);
@@ -359,8 +376,8 @@
memset(buf, 0, sizeof(buf));
- rv = read(h->fd, &buf, GROUPD_MSGLEN);
- if (rv != GROUPD_MSGLEN)
+ rv = do_read(h->fd, &buf, GROUPD_MSGLEN);
+ if (rv < 0)
goto out;
act = get_action(buf);
@@ -378,6 +395,10 @@
count = atoi(argv[4]);
nodeids = malloc(count * sizeof(int));
+ if (!nodeids) {
+ rv = -ENOMEM;
+ goto out;
+ }
get_nodeids(p, count, nodeids);
h->cbs.start(h, h->private, argv[1], atoi(argv[2]),
@@ -403,9 +424,8 @@
case DO_SET_ID:
get_args(buf, &argc, argv, ' ', 3);
- /* FIXME: id is unsigned, use strtoul() here */
-
- h->cbs.set_id(h, h->private, argv[1], atoi(argv[2]));
+ h->cbs.set_id(h, h->private, argv[1],
+ (unsigned int) strtoul(argv[2], NULL, 10));
break;
case DO_DELIVER:
@@ -472,9 +492,9 @@
if (rv < 0)
goto out;
- rv = read(fd, &data_buf, sizeof(data_buf));
-
- /* FIXME: check rv */
+ rv = do_read(fd, &data_buf, sizeof(data_buf));
+ if (rv < 0)
+ goto out;
memcpy(data, data_buf, sizeof(group_data_t));
rv = 0;
next reply other threads:[~2006-09-07 19:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-07 19:24 teigland [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-10-13 17:15 [Cluster-devel] cluster/group/lib libgroup.c teigland
2006-10-24 15:11 teigland
2006-11-17 16:30 teigland
2006-11-17 16:30 teigland
2006-11-20 22:54 rpeterso
2007-04-30 16:56 fabbione
2007-10-26 20:41 teigland
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=20060907192409.13137.qmail@sourceware.org \
--to=teigland@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.