summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch
diff options
context:
space:
mode:
authorAlistair Francis <Alistair.Francis@wdc.com>2019-05-02 04:09:27 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-05-03 06:11:57 +0100
commit69085ccb296b35b0b0ed67c871f0f60106c27a48 (patch)
tree22db1a527ff808d887da933a78c12408393c9280 /meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch
parent3d19803cbd0869dd55dbc778dacf6f6397374457 (diff)
downloadpoky-69085ccb296b35b0b0ed67c871f0f60106c27a48.tar.gz
qemu: Upgrade from 3.1.0 to 4.0.0
This commit upgrade QEMU to the latest 4.0.0 release. - The COPYING.LIB file has changed SHA to: "Synchronize the LGPL 2.1 with the version from gnu.org" - SDL 1.2 has been removed, along with the --with-sdlabi command line arg - The backported patches have been removed - Al the other patches have been refreshed and the numbering has been updated (From OE-Core rev: fed2a0f37a76732cd3de1b127d6902fb16dd4e05) Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch')
-rw-r--r--meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch240
1 files changed, 0 insertions, 240 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch b/meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch
deleted file mode 100644
index e5a2d4abca..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0008-chardev-connect-socket-to-a-spawned-command.patch
+++ /dev/null
@@ -1,240 +0,0 @@
1From 9c1e976290e87a83ab1bfe38eb7ff3521ff0d684 Mon Sep 17 00:00:00 2001
2From: Alistair Francis <alistair.francis@xilinx.com>
3Date: Thu, 21 Dec 2017 11:35:16 -0800
4Subject: [PATCH] chardev: connect socket to a spawned command
5
6The command is started in a shell (sh -c) with stdin connect to QEMU
7via a Unix domain stream socket. QEMU then exchanges data via its own
8end of the socket, just like it normally does.
9
10"-chardev socket" supports some ways of connecting via protocols like
11telnet, but that is only a subset of the functionality supported by
12tools socat. To use socat instead, for example to connect via a socks
13proxy, use:
14
15 -chardev 'socket,id=socat,cmd=exec socat FD:0 SOCKS4A:socks-proxy.localdomain:example.com:9999,,socksuser=nobody' \
16 -device usb-serial,chardev=socat
17
18Beware that commas in the command must be escaped as double commas.
19
20Or interactively in the console:
21 (qemu) chardev-add socket,id=cat,cmd=cat
22 (qemu) device_add usb-serial,chardev=cat
23 ^ac
24 # cat >/dev/ttyUSB0
25 hello
26 hello
27
28Another usage is starting swtpm from inside QEMU. swtpm will
29automatically shut down once it looses the connection to the parent
30QEMU, so there is no risk of lingering processes:
31
32 -chardev 'socket,id=chrtpm0,cmd=exec swtpm socket --terminate --ctrl type=unixio,,clientfd=0 --tpmstate dir=... --log file=swtpm.log' \
33 -tpmdev emulator,id=tpm0,chardev=chrtpm0 \
34 -device tpm-tis,tpmdev=tpm0
35
36The patch was discussed upstream, but QEMU developers believe that the
37code calling QEMU should be responsible for managing additional
38processes. In OE-core, that would imply enhancing runqemu and
39oeqa. This patch is a simpler solution.
40
41Because it is not going upstream, the patch was written so that it is
42as simple as possible.
43
44Upstream-Status: Inappropriate [embedded specific]
45
46Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
47
48---
49 chardev/char-socket.c | 102 ++++++++++++++++++++++++++++++++++++++++++
50 chardev/char.c | 3 ++
51 qapi/char.json | 5 +++
52 3 files changed, 110 insertions(+)
53
54diff --git a/chardev/char-socket.c b/chardev/char-socket.c
55index eaa8e8b6..959ed183 100644
56--- a/chardev/char-socket.c
57+++ b/chardev/char-socket.c
58@@ -987,6 +987,68 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
59 return false;
60 }
61
62+#ifndef _WIN32
63+static void chardev_open_socket_cmd(Chardev *chr,
64+ const char *cmd,
65+ Error **errp)
66+{
67+ int fds[2] = { -1, -1 };
68+ QIOChannelSocket *sioc = NULL;
69+ pid_t pid = -1;
70+ const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
71+
72+ /*
73+ * We need a Unix domain socket for commands like swtpm and a single
74+ * connection, therefore we cannot use qio_channel_command_new_spawn()
75+ * without patching it first. Duplicating the functionality is easier.
76+ */
77+ if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds)) {
78+ error_setg_errno(errp, errno, "Error creating socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC)");
79+ goto error;
80+ }
81+
82+ pid = qemu_fork(errp);
83+ if (pid < 0) {
84+ goto error;
85+ }
86+
87+ if (!pid) {
88+ /* child */
89+ dup2(fds[1], STDIN_FILENO);
90+ execv(argv[0], (char * const *)argv);
91+ _exit(1);
92+ }
93+
94+ /*
95+ * Hand over our end of the socket pair to the qio channel.
96+ *
97+ * We don't reap the child because it is expected to keep
98+ * running. We also don't support the "reconnect" option for the
99+ * same reason.
100+ */
101+ sioc = qio_channel_socket_new_fd(fds[0], errp);
102+ if (!sioc) {
103+ goto error;
104+ }
105+ fds[0] = -1;
106+
107+ g_free(chr->filename);
108+ chr->filename = g_strdup_printf("cmd:%s", cmd);
109+ tcp_chr_new_client(chr, sioc);
110+
111+ error:
112+ if (fds[0] >= 0) {
113+ close(fds[0]);
114+ }
115+ if (fds[1] >= 0) {
116+ close(fds[1]);
117+ }
118+ if (sioc) {
119+ object_unref(OBJECT(sioc));
120+ }
121+}
122+#endif
123+
124 static void qmp_chardev_open_socket(Chardev *chr,
125 ChardevBackend *backend,
126 bool *be_opened,
127@@ -994,6 +1056,9 @@ static void qmp_chardev_open_socket(Chardev *chr,
128 {
129 SocketChardev *s = SOCKET_CHARDEV(chr);
130 ChardevSocket *sock = backend->u.socket.data;
131+#ifndef _WIN32
132+ const char *cmd = sock->cmd;
133+#endif
134 bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
135 bool is_listen = sock->has_server ? sock->server : true;
136 bool is_telnet = sock->has_telnet ? sock->telnet : false;
137@@ -1072,6 +1137,14 @@ static void qmp_chardev_open_socket(Chardev *chr,
138 s->reconnect_time = reconnect;
139 }
140
141+#ifndef _WIN32
142+ if (cmd) {
143+ chardev_open_socket_cmd(chr, cmd, errp);
144+
145+ /* everything ready (or failed permanently) before we return */
146+ *be_opened = true;
147+ } else
148+#endif
149 if (s->reconnect_time) {
150 tcp_chr_connect_async(chr);
151 } else {
152@@ -1131,9 +1204,26 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
153 const char *port = qemu_opt_get(opts, "port");
154 const char *fd = qemu_opt_get(opts, "fd");
155 const char *tls_creds = qemu_opt_get(opts, "tls-creds");
156+#ifndef _WIN32
157+ const char *cmd = qemu_opt_get(opts, "cmd");
158+#endif
159 SocketAddressLegacy *addr;
160 ChardevSocket *sock;
161
162+#ifndef _WIN32
163+ if (cmd) {
164+ /*
165+ * Here we have to ensure that no options are set which are incompatible with
166+ * spawning a command, otherwise unmodified code that doesn't know about
167+ * command spawning (like socket_reconnect_timeout()) might get called.
168+ */
169+ if (path || is_listen || is_telnet || is_tn3270 || reconnect || host || port || tls_creds) {
170+ error_setg(errp, "chardev: socket: cmd does not support any additional options");
171+ return;
172+ }
173+ } else
174+#endif
175+
176 if ((!!path + !!fd + !!host) != 1) {
177 error_setg(errp,
178 "Exactly one of 'path', 'fd' or 'host' required");
179@@ -1180,12 +1270,24 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
180 sock->reconnect = reconnect;
181 sock->tls_creds = g_strdup(tls_creds);
182
183+#ifndef _WIN32
184+ sock->cmd = g_strdup(cmd);
185+#endif
186+
187 addr = g_new0(SocketAddressLegacy, 1);
188+#ifndef _WIN32
189+ if (path || cmd) {
190+#else
191 if (path) {
192+#endif
193 UnixSocketAddress *q_unix;
194 addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
195 q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
196+#ifndef _WIN32
197+ q_unix->path = cmd ? g_strdup_printf("cmd:%s", cmd) : g_strdup(path);
198+#else
199 q_unix->path = g_strdup(path);
200+#endif
201 } else if (host) {
202 addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
203 addr->u.inet.data = g_new(InetSocketAddress, 1);
204diff --git a/chardev/char.c b/chardev/char.c
205index 152dde53..62d5b578 100644
206--- a/chardev/char.c
207+++ b/chardev/char.c
208@@ -818,6 +818,9 @@ QemuOptsList qemu_chardev_opts = {
209 },{
210 .name = "path",
211 .type = QEMU_OPT_STRING,
212+ },{
213+ .name = "cmd",
214+ .type = QEMU_OPT_STRING,
215 },{
216 .name = "host",
217 .type = QEMU_OPT_STRING,
218diff --git a/qapi/char.json b/qapi/char.json
219index 79bac598..97bd161a 100644
220--- a/qapi/char.json
221+++ b/qapi/char.json
222@@ -242,6 +242,10 @@
223 #
224 # @addr: socket address to listen on (server=true)
225 # or connect to (server=false)
226+# @cmd: command to run via "sh -c" with stdin as one end of
227+# a AF_UNIX SOCK_DSTREAM socket pair. The other end
228+# is used by the chardev. Either an addr or a cmd can
229+# be specified, but not both.
230 # @tls-creds: the ID of the TLS credentials object (since 2.6)
231 # @server: create server socket (default: true)
232 # @wait: wait for incoming connection on server
233@@ -261,6 +265,7 @@
234 # Since: 1.4
235 ##
236 { 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddressLegacy',
237+ '*cmd' : 'str',
238 '*tls-creds' : 'str',
239 '*server' : 'bool',
240 '*wait' : 'bool',