commit f952b0f11c7f78bd362ad1d991e5adfa6f0f458b
Author: Juergen Gross <jgross@suse.com>
Date:   Fri Feb 24 07:21:41 2017 +0100

    xenstore: Split out XS_CONTROL action to dedicated source file
    
    Move the XS_CONTROL handling of xenstored to a new source file
    xenstored_control.c.
    
    In order to avoid making get_string() in xenstored_core.c globally
    visible use strlen() instead, which is save in this context due to
    xs_count_strings() before returned a value > 1.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Wei Liu <wei.liu2@citrix.com>

Index: xen-4.4.4-testing/tools/xenstore/Makefile
===================================================================
--- xen-4.4.4-testing.orig/tools/xenstore/Makefile
+++ xen-4.4.4-testing/tools/xenstore/Makefile
@@ -12,7 +12,9 @@ CLIENTS := xenstore-exists xenstore-list
 CLIENTS += xenstore-write xenstore-ls xenstore-watch
 CLIENTS_DOMU := $(patsubst xenstore-%,domu-xenstore-%,$(CLIENTS))
 
-XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
+XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o
+XENSTORED_OBJS += xenstored_transaction.o xenstored_control.o
+XENSTORED_OBJS += xs_lib.o talloc.o utils.o tdb.o hashtable.o
 
 XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_linux.o xenstored_posix.o
 XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o xenstored_probes.o
Index: xen-4.4.4-testing/tools/xenstore/xenstored_control.c
===================================================================
--- /dev/null
+++ xen-4.4.4-testing/tools/xenstore/xenstored_control.c
@@ -0,0 +1,46 @@
+/*
+    Interactive commands for Xen Store Daemon.
+    Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <errno.h>
+
+#include "utils.h"
+#include "xenstored_core.h"
+#include "xenstored_control.h"
+
+int do_control(struct connection *conn, struct buffered_data *in)
+{
+	int num;
+
+	if (conn->id != 0)
+		return EACCES;
+
+	num = xs_count_strings(in->buffer, in->used);
+
+	if (streq(in->buffer, "print")) {
+		if (num < 2)
+			return EINVAL;
+		xprintf("control: %s", in->buffer + strlen(in->buffer) + 1);
+	}
+
+	if (streq(in->buffer, "check"))
+		check_store();
+
+	send_ack(conn, XS_CONTROL);
+
+	return 0;
+}
Index: xen-4.4.4-testing/tools/xenstore/xenstored_control.h
===================================================================
--- /dev/null
+++ xen-4.4.4-testing/tools/xenstore/xenstored_control.h
@@ -0,0 +1,19 @@
+/*
+    Interactive commands for Xen Store Daemon.
+    Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+int do_control(struct connection *conn, struct buffered_data *in);
Index: xen-4.4.4-testing/tools/xenstore/xenstored_core.c
===================================================================
--- xen-4.4.4-testing.orig/tools/xenstore/xenstored_core.c
+++ xen-4.4.4-testing/tools/xenstore/xenstored_core.c
@@ -50,6 +50,7 @@
 #include "xenstored_watch.h"
 #include "xenstored_transaction.h"
 #include "xenstored_domain.h"
+#include "xenstored_control.h"
 #include "xenctrl.h"
 #include "tdb.h"
 
@@ -75,7 +76,6 @@ static TDB_CONTEXT *tdb_ctx = NULL;
 static bool trigger_talloc_report = false;
 
 static void corrupt(struct connection *conn, const char *fmt, ...);
-static void check_store(void);
 static const char *sockmsg_string(enum xsd_sockmsg_type type);
 
 #define log(...)							\
@@ -1252,29 +1252,6 @@ static int do_set_perms(struct connectio
 	return 0;
 }
 
-static int do_control(struct connection *conn, struct buffered_data *in)
-{
-	int num;
-
-	if (conn->id != 0)
-		return EACCES;
-
-	num = xs_count_strings(in->buffer, in->used);
-
-	if (streq(in->buffer, "print")) {
-		if (num < 2)
-			return EINVAL;
-		xprintf("control: %s", in->buffer + get_string(in, 0));
-	}
-
-	if (streq(in->buffer, "check"))
-		check_store();
-
-	send_ack(conn, XS_CONTROL);
-
-	return 0;
-}
-
 static struct {
 	const char *str;
 	int (*func)(struct connection *conn, struct buffered_data *in);
@@ -1756,7 +1733,7 @@ static void clean_store(struct hashtable
 }
 
 
-static void check_store(void)
+void check_store(void)
 {
 	char * root = talloc_strdup(NULL, "/");
 	struct hashtable * reachable =
Index: xen-4.4.4-testing/tools/xenstore/xenstored_core.h
===================================================================
--- xen-4.4.4-testing.orig/tools/xenstore/xenstored_core.h
+++ xen-4.4.4-testing/tools/xenstore/xenstored_core.h
@@ -156,7 +156,7 @@ TDB_CONTEXT *tdb_context(struct connecti
 bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb);
 
 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
-
+void check_store(void);
 
 /* Is this a valid node name? */
 bool is_valid_nodename(const char *node);
