forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch-0018-xenstore-Split-out-XS_CONTROL-action-to-dedicated-so.patch
192 lines (177 loc) · 6.33 KB
/
patch-0018-xenstore-Split-out-XS_CONTROL-action-to-dedicated-so.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
From 360d157957193557c3341cd47f6df3a7b0ea02cf Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Fri, 24 Feb 2017 07:21:41 +0100
Subject: [PATCH 18/25] 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>
---
tools/xenstore/Makefile | 4 ++-
tools/xenstore/xenstored_control.c | 46 ++++++++++++++++++++++++++++++
tools/xenstore/xenstored_control.h | 19 ++++++++++++
tools/xenstore/xenstored_core.c | 27 ++----------------
tools/xenstore/xenstored_core.h | 2 +-
5 files changed, 71 insertions(+), 27 deletions(-)
create mode 100644 tools/xenstore/xenstored_control.c
create mode 100644 tools/xenstore/xenstored_control.h
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 9cb54def2178..5e50a9232c4e 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -23,7 +23,9 @@ LDFLAGS += $(LDFLAGS-y)
CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
CLIENTS += xenstore-write xenstore-ls xenstore-watch
-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_posix.o
XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o xenstored_probes.o
diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
new file mode 100644
index 000000000000..f169d238d1a2
--- /dev/null
+++ b/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;
+}
diff --git a/tools/xenstore/xenstored_control.h b/tools/xenstore/xenstored_control.h
new file mode 100644
index 000000000000..207e0a6fa352
--- /dev/null
+++ b/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);
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 413ac2f01a0b..ee1cef0f8fea 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -51,6 +51,7 @@
#include "xenstored_watch.h"
#include "xenstored_transaction.h"
#include "xenstored_domain.h"
+#include "xenstored_control.h"
#include "tdb.h"
#include "hashtable.h"
@@ -85,7 +86,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(...) \
@@ -1284,29 +1284,6 @@ static int do_set_perms(struct connection *conn, struct buffered_data *in)
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);
@@ -1818,7 +1795,7 @@ static void clean_store(struct hashtable *reachable)
}
-static void check_store(void)
+void check_store(void)
{
char * root = talloc_strdup(NULL, "/");
struct hashtable * reachable =
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 77024644275e..6a58c65783e4 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -164,7 +164,7 @@ TDB_CONTEXT *tdb_context(struct connection *conn);
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);
--
2.25.4