1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "qapi/type-helpers.h"
22#include "qemu/error-report.h"
23#include "channel.h"
24#include "exec.h"
25#include "migration.h"
26#include "io/channel-command.h"
27#include "trace.h"
28#include "qemu/cutils.h"
29
30#ifdef WIN32
31const char *exec_get_cmd_path(void)
32{
33 g_autofree char *detected_path = g_new(char, MAX_PATH);
34 if (GetSystemDirectoryA(detected_path, MAX_PATH) == 0) {
35 warn_report("Could not detect cmd.exe path, using default.");
36 return "C:\\Windows\\System32\\cmd.exe";
37 }
38 pstrcat(detected_path, MAX_PATH, "\\cmd.exe");
39 return g_steal_pointer(&detected_path);
40}
41#endif
42
43void exec_start_outgoing_migration(MigrationState *s, strList *command,
44 Error **errp)
45{
46 QIOChannel *ioc = NULL;
47 g_auto(GStrv) argv = strv_from_str_list(command);
48 const char * const *args = (const char * const *) argv;
49 g_autofree char *new_command = g_strjoinv(" ", (char **)argv);
50
51 trace_migration_exec_outgoing(new_command);
52 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp));
53 if (!ioc) {
54 return;
55 }
56
57 qio_channel_set_name(ioc, "migration-exec-outgoing");
58 migration_channel_connect(s, ioc, NULL, NULL);
59 object_unref(OBJECT(ioc));
60}
61
62static gboolean exec_accept_incoming_migration(QIOChannel *ioc,
63 GIOCondition condition,
64 gpointer opaque)
65{
66 migration_channel_process_incoming(ioc);
67 object_unref(OBJECT(ioc));
68 return G_SOURCE_REMOVE;
69}
70
71void exec_start_incoming_migration(strList *command, Error **errp)
72{
73 QIOChannel *ioc;
74 g_auto(GStrv) argv = strv_from_str_list(command);
75 const char * const *args = (const char * const *) argv;
76 g_autofree char *new_command = g_strjoinv(" ", (char **)argv);
77
78 trace_migration_exec_incoming(new_command);
79 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp));
80 if (!ioc) {
81 return;
82 }
83
84 qio_channel_set_name(ioc, "migration-exec-incoming");
85 qio_channel_add_watch_full(ioc, G_IO_IN,
86 exec_accept_incoming_migration,
87 NULL, NULL,
88 g_main_context_get_thread_default());
89}
90