References: bsc#1022555

From cf4b07a883cb5919112fd9adfc29f5550e488168 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Wed, 15 Mar 2017 13:10:11 +0100
Subject: [PATCH 1/3] xenstore: let write_node() and some callers return errno

Instead of setting errno and returning true or false return the error
value directly.

In order to ensure all call sites have been changed according to the
modification rename the functions to xs_*.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/xenstore/xenstored_core.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

Index: xen-4.0.3-testing/tools/xenstore/xenstored_core.c
===================================================================
--- xen-4.0.3-testing.orig/tools/xenstore/xenstored_core.c
+++ xen-4.0.3-testing/tools/xenstore/xenstored_core.c
@@ -404,7 +404,7 @@ static struct node *read_node(struct con
 	return node;
 }
 
-static bool write_node(struct connection *conn, struct node *node)
+static int xs_write_node(struct connection *conn, struct node *node)
 {
 	/*
 	 * conn will be null when this is called from manual_node.
@@ -445,10 +445,10 @@ static bool write_node(struct connection
 		corrupt(conn, "Write of %s failed", key.dptr);
 		goto error;
 	}
-	return true;
+	return 0;
  error:
 	errno = ENOSPC;
-	return false;
+	return errno;
 }
 
 static enum xs_perm_type perm_for_conn(struct connection *conn,
@@ -983,7 +983,7 @@ static struct node *create_node(struct c
 	/* We write out the nodes down, setting destructor in case
 	 * something goes wrong. */
 	for (i = node; i; i = i->parent) {
-		if (!write_node(conn, i)) {
+		if (xs_write_node(conn, i)) {
 			domain_entry_dec(conn, i);
 			return NULL;
 		}
@@ -1023,7 +1023,7 @@ static int do_write(struct connection *c
 	} else {
 		node->data = in->buffer + offset;
 		node->datalen = datalen;
-		if (!write_node(conn, node))
+		if (xs_write_node(conn, node))
 			return errno;
 	}
 
@@ -1096,28 +1096,28 @@ static void memdel(void *mem, unsigned o
 }
 
 
-static bool remove_child_entry(struct connection *conn, struct node *node,
-			       size_t offset)
+static int xs_remove_child_entry(struct connection *conn, struct node *node,
+			      size_t offset)
 {
 	size_t childlen = strlen(node->children + offset);
 	memdel(node->children, offset, childlen + 1, node->childlen);
 	node->childlen -= childlen + 1;
-	return write_node(conn, node);
+	return xs_write_node(conn, node);
 }
 
 
-static bool delete_child(struct connection *conn,
-			 struct node *node, const char *childname)
+static int xs_delete_child(struct connection *conn,
+			struct node *node, const char *childname)
 {
 	unsigned int i;
 
 	for (i = 0; i < node->childlen; i += strlen(node->children+i) + 1) {
 		if (streq(node->children+i, childname)) {
-			return remove_child_entry(conn, node, i);
+			return xs_remove_child_entry(conn, node, i);
 		}
 	}
 	corrupt(conn, "Can't find child '%s' in %s", childname, node->name);
-	return false;
+	return ENOENT;
 }
 
 
@@ -1137,7 +1137,7 @@ static int _rm(struct connection *conn,
 	if (!parent)
 		return (errno == ENOMEM) ? ENOMEM : EINVAL;
 
-	if (!delete_child(conn, parent, basename(name)))
+	if (xs_delete_child(conn, parent, basename(name)))
 		return EINVAL;
 
 	delete_node(conn, node, true);
@@ -1241,7 +1241,7 @@ static int do_set_perms(struct connectio
 	node->num_perms = num;
 	domain_entry_inc(conn, node);
 
-	if (!write_node(conn, node))
+	if (xs_write_node(conn, node))
 		return errno;
 
 	wrl_apply_debit_direct(conn);
@@ -1497,7 +1497,7 @@ static void manual_node(const char *name
 	if (child)
 		node->childlen = strlen(child) + 1;
 
-	if (!write_node(NULL, node))
+	if (xs_write_node(NULL, node))
 		barf_perror("Could not create initial node %s", name);
 	talloc_free(node);
 }
@@ -1635,7 +1635,7 @@ static int check_store_(const char *name
 					    childname);
 
 					if (recovery) {
-						remove_child_entry(NULL, node,
+						xs_remove_child_entry(NULL, node,
 								   i);
 						i -= childlen + 1;
 					}
@@ -1657,7 +1657,7 @@ static int check_store_(const char *name
 				    childname);
 
 				if (recovery) {
-					remove_child_entry(NULL, node, i);
+					xs_remove_child_entry(NULL, node, i);
 					i -= childlen + 1;
 				}
 			} else {
