4 * Copyright IBM, Corp. 2008
5 * Copyright Dell MessageOne 2008
6 * Copyright Red Hat, Inc. 2015-2016
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Charles Duffy <charles_duffy@messageone.com>
11 * Daniel P. Berrange <berrange@redhat.com>
13 * This work is licensed under the terms of the GNU GPL, version 2. See
14 * the COPYING file in the top-level directory.
16 * Contributions after 2012-01-13 are licensed under the terms of the
17 * GNU GPL, version 2 or (at your option) any later version.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
24 #include "migration.h"
25 #include "io/channel-command.h"
27 #include "qemu/cutils.h"
30 const char *exec_get_cmd_path(void)
32 g_autofree
char *detected_path
= g_new(char, MAX_PATH
);
33 if (GetSystemDirectoryA(detected_path
, MAX_PATH
) == 0) {
34 warn_report("Could not detect cmd.exe path, using default.");
35 return "C:\\Windows\\System32\\cmd.exe";
37 pstrcat(detected_path
, MAX_PATH
, "\\cmd.exe");
38 return g_steal_pointer(&detected_path
);
42 /* provides the length of strList */
44 str_list_length(strList
*list
)
49 for (elem
= list
; elem
!= NULL
; elem
= elem
->next
) {
57 init_exec_array(strList
*command
, char **argv
, Error
**errp
)
62 for (lst
= command
; lst
; lst
= lst
->next
) {
63 argv
[i
++] = lst
->value
;
70 void exec_start_outgoing_migration(MigrationState
*s
, strList
*command
,
75 int length
= str_list_length(command
);
76 g_auto(GStrv
) argv
= (char **) g_new0(const char *, length
+ 1);
78 init_exec_array(command
, argv
, errp
);
79 g_autofree
char *new_command
= g_strjoinv(" ", (char **)argv
);
81 trace_migration_exec_outgoing(new_command
);
83 qio_channel_command_new_spawn(
84 (const char * const *) g_steal_pointer(&argv
),
91 qio_channel_set_name(ioc
, "migration-exec-outgoing");
92 migration_channel_connect(s
, ioc
, NULL
, NULL
);
93 object_unref(OBJECT(ioc
));
96 static gboolean
exec_accept_incoming_migration(QIOChannel
*ioc
,
97 GIOCondition condition
,
100 migration_channel_process_incoming(ioc
);
101 object_unref(OBJECT(ioc
));
102 return G_SOURCE_REMOVE
;
105 void exec_start_incoming_migration(strList
*command
, Error
**errp
)
109 int length
= str_list_length(command
);
110 g_auto(GStrv
) argv
= (char **) g_new0(const char *, length
+ 1);
112 init_exec_array(command
, argv
, errp
);
113 g_autofree
char *new_command
= g_strjoinv(" ", (char **)argv
);
115 trace_migration_exec_incoming(new_command
);
117 qio_channel_command_new_spawn(
118 (const char * const *) g_steal_pointer(&argv
),
125 qio_channel_set_name(ioc
, "migration-exec-incoming");
126 qio_channel_add_watch_full(ioc
, G_IO_IN
,
127 exec_accept_incoming_migration
,
129 g_main_context_get_thread_default());