aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xenstored_core.c
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/xenstore/xenstored_core.c
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/xenstore/xenstored_core.c')
-rw-r--r--tools/xenstore/xenstored_core.c38
1 files changed, 30 insertions, 8 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;
}