aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-07-24 18:28:48 +0100
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-07-24 18:28:48 +0100
commit698543a3139d11d724d2b7b0622a7ea42051a696 (patch)
tree0aa2dbd1eb56627c5d7a060b8bb7701f3f378498 /tools
parente313dc3ed8a13242ce9a9c5cb658d482c44a192e (diff)
downloadxen-698543a3139d11d724d2b7b0622a7ea42051a696.tar.gz
xen-698543a3139d11d724d2b7b0622a7ea42051a696.tar.bz2
xen-698543a3139d11d724d2b7b0622a7ea42051a696.zip
xenstore: Small cleanups and fixes.
1. readfd/writefd account for EINTR/EAGAIN errno returns. 2. Handle zero return from ->read() and ->write() handlers symmetrically. 3. Fix some indentation issues (use hard tabs). Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/xenstore/xenstored_core.c38
-rw-r--r--tools/xenstore/xenstored_domain.c5
-rw-r--r--tools/xenstore/xenstored_watch.c5
3 files changed, 35 insertions, 13 deletions
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index f62de82b77..1081103459 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -1266,7 +1266,7 @@ static void handle_input(struct connection *conn)
if (in->inhdr) {
bytes = conn->read(conn, in->hdr.raw + in->used,
sizeof(in->hdr) - in->used);
- if (bytes <= 0)
+ if (bytes < 0)
goto bad_client;
in->used += bytes;
if (in->used != sizeof(in->hdr))
@@ -1288,7 +1288,7 @@ static void handle_input(struct connection *conn)
bytes = conn->read(conn, in->buffer + in->used,
in->hdr.msg.len - in->used);
- if (bytes <= 0)
+ if (bytes < 0)
goto bad_client;
in->used += bytes;
@@ -1341,12 +1341,34 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
static int writefd(struct connection *conn, const void *data, unsigned int len)
{
- return write(conn->fd, data, len);
+ int rc;
+
+ while ((rc = write(conn->fd, data, len)) < 0) {
+ if (errno == EAGAIN) {
+ rc = 0;
+ break;
+ }
+ if (errno != EINTR)
+ break;
+ }
+
+ return rc;
}
static int readfd(struct connection *conn, void *data, unsigned int len)
{
- return read(conn->fd, data, len);
+ int rc;
+
+ while ((rc = read(conn->fd, data, len)) < 0) {
+ if (errno == EAGAIN) {
+ rc = 0;
+ break;
+ }
+ if (errno != EINTR)
+ break;
+ }
+
+ return rc;
}
static void accept_connection(int sock, bool canwrite)
@@ -1439,13 +1461,13 @@ static void setup_structure(void)
static unsigned int hash_from_key_fn(void *k)
{
char *str = k;
- unsigned int hash = 5381;
- char c;
+ unsigned int hash = 5381;
+ char c;
- while ((c = *str++))
+ while ((c = *str++))
hash = ((hash << 5) + hash) + (unsigned int)c;
- return hash;
+ return hash;
}
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index c51e2c73b9..d166c0556e 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -76,7 +76,6 @@ struct domain
static LIST_HEAD(domains);
-/* FIXME: Mark connection as broken (close it?) when this happens. */
static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
{
return ((prod - cons) <= XENSTORE_RING_SIZE);
@@ -102,7 +101,8 @@ static const void *get_input_chunk(XENSTORE_RING_IDX cons,
return buf + MASK_XENSTORE_IDX(cons);
}
-static int writechn(struct connection *conn, const void *data, unsigned int len)
+static int writechn(struct connection *conn,
+ const void *data, unsigned int len)
{
uint32_t avail;
void *dest;
@@ -113,6 +113,7 @@ static int writechn(struct connection *conn, const void *data, unsigned int len)
cons = intf->rsp_cons;
prod = intf->rsp_prod;
mb();
+
if (!check_indexes(cons, prod)) {
errno = EIO;
return -1;
diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_watch.c
index 27e082a24f..f5692f83e5 100644
--- a/tools/xenstore/xenstored_watch.c
+++ b/tools/xenstore/xenstored_watch.c
@@ -73,11 +73,10 @@ static void add_event(struct connection *conn,
data = talloc_array(watch, char, len);
strcpy(data, name);
strcpy(data + strlen(name) + 1, watch->token);
- send_reply(conn, XS_WATCH_EVENT, data, len);
+ send_reply(conn, XS_WATCH_EVENT, data, len);
talloc_free(data);
}
-/* FIXME: we fail to fire on out of memory. Should drop connections. */
void fire_watches(struct connection *conn, const char *name, bool recurse)
{
struct connection *i;
@@ -130,7 +129,7 @@ void do_watch(struct connection *conn, struct buffered_data *in)
/* Check for duplicates. */
list_for_each_entry(watch, &conn->watches, list) {
if (streq(watch->node, vec[0]) &&
- streq(watch->token, vec[1])) {
+ streq(watch->token, vec[1])) {
send_error(conn, EEXIST);
return;
}