audio: make playback packet length calculation exact
[qemu/ar7.git] / migration / exec.c
blob38604d73a69ae2458df9c97ece48909fa41ae445
1 /*
2 * QEMU live migration
4 * Copyright IBM, Corp. 2008
5 * Copyright Dell MessageOne 2008
6 * Copyright Red Hat, Inc. 2015-2016
8 * Authors:
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 "channel.h"
22 #include "exec.h"
23 #include "migration.h"
24 #include "io/channel-command.h"
25 #include "trace.h"
26 #include "qemu/cutils.h"
28 #ifdef WIN32
29 const char *exec_get_cmd_path(void);
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);
40 #endif
42 void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp)
44 QIOChannel *ioc;
46 #ifdef WIN32
47 const char *argv[] = { exec_get_cmd_path(), "/c", command, NULL };
48 #else
49 const char *argv[] = { "/bin/sh", "-c", command, NULL };
50 #endif
52 trace_migration_exec_outgoing(command);
53 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
54 O_RDWR,
55 errp));
56 if (!ioc) {
57 return;
60 qio_channel_set_name(ioc, "migration-exec-outgoing");
61 migration_channel_connect(s, ioc, NULL, NULL);
62 object_unref(OBJECT(ioc));
65 static gboolean exec_accept_incoming_migration(QIOChannel *ioc,
66 GIOCondition condition,
67 gpointer opaque)
69 migration_channel_process_incoming(ioc);
70 object_unref(OBJECT(ioc));
71 return G_SOURCE_REMOVE;
74 void exec_start_incoming_migration(const char *command, Error **errp)
76 QIOChannel *ioc;
78 #ifdef WIN32
79 const char *argv[] = { exec_get_cmd_path(), "/c", command, NULL };
80 #else
81 const char *argv[] = { "/bin/sh", "-c", command, NULL };
82 #endif
84 trace_migration_exec_incoming(command);
85 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
86 O_RDWR,
87 errp));
88 if (!ioc) {
89 return;
92 qio_channel_set_name(ioc, "migration-exec-incoming");
93 qio_channel_add_watch_full(ioc, G_IO_IN,
94 exec_accept_incoming_migration,
95 NULL, NULL,
96 g_main_context_get_thread_default());