/src/qemu/migration/exec.c
Line | Count | Source |
1 | | /* |
2 | | * QEMU live migration |
3 | | * |
4 | | * Copyright IBM, Corp. 2008 |
5 | | * Copyright Dell MessageOne 2008 |
6 | | * Copyright Red Hat, Inc. 2015-2016 |
7 | | * |
8 | | * Authors: |
9 | | * Anthony Liguori <aliguori@us.ibm.com> |
10 | | * Charles Duffy <charles_duffy@messageone.com> |
11 | | * Daniel P. Berrange <berrange@redhat.com> |
12 | | * |
13 | | * This work is licensed under the terms of the GNU GPL, version 2. See |
14 | | * the COPYING file in the top-level directory. |
15 | | * |
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. |
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 |
31 | | const 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 | | |
43 | | QIOChannel *exec_connect_outgoing(MigrationState *s, strList *command, |
44 | | Error **errp) |
45 | 0 | { |
46 | 0 | QIOChannel *ioc = NULL; |
47 | 0 | g_auto(GStrv) argv = strv_from_str_list(command); |
48 | 0 | const char * const *args = (const char * const *) argv; |
49 | 0 | g_autofree char *new_command = g_strjoinv(" ", (char **)argv); |
50 | |
|
51 | 0 | trace_migration_exec_outgoing(new_command); |
52 | 0 | ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); |
53 | 0 | if (!ioc) { |
54 | 0 | return NULL; |
55 | 0 | } |
56 | | |
57 | 0 | qio_channel_set_name(ioc, "migration-exec-outgoing"); |
58 | 0 | return ioc; |
59 | 0 | } |
60 | | |
61 | | static gboolean exec_accept_incoming_migration(QIOChannel *ioc, |
62 | | GIOCondition condition, |
63 | | gpointer opaque) |
64 | 0 | { |
65 | 0 | migration_channel_process_incoming(ioc); |
66 | 0 | object_unref(OBJECT(ioc)); |
67 | 0 | return G_SOURCE_REMOVE; |
68 | 0 | } |
69 | | |
70 | | void exec_connect_incoming(strList *command, Error **errp) |
71 | 0 | { |
72 | 0 | QIOChannel *ioc; |
73 | 0 | g_auto(GStrv) argv = strv_from_str_list(command); |
74 | 0 | const char * const *args = (const char * const *) argv; |
75 | 0 | g_autofree char *new_command = g_strjoinv(" ", (char **)argv); |
76 | |
|
77 | 0 | trace_migration_exec_incoming(new_command); |
78 | 0 | ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); |
79 | 0 | if (!ioc) { |
80 | 0 | return; |
81 | 0 | } |
82 | | |
83 | 0 | qio_channel_set_name(ioc, "migration-exec-incoming"); |
84 | 0 | qio_channel_add_watch_full(ioc, G_IO_IN, |
85 | 0 | exec_accept_incoming_migration, |
86 | 0 | NULL, NULL, |
87 | 0 | g_main_context_get_thread_default()); |
88 | 0 | } |