int qmp_fd;
bool irq_level[MAX_IRQ];
GString *rx;
- gchar *pid_file; /* QEMU PID file */
int child_pid; /* Child process created to execute QEMU */
+ pid_t qemu_pid; /* QEMU process spawned by our child */
char *socket_path, *qmp_socket_path;
};
return ret;
}
-static pid_t qtest_qemu_pid(QTestState *s)
+static pid_t read_pid_file(const char *pid_file)
{
FILE *f;
char buffer[1024];
pid_t pid = -1;
- f = fopen(s->pid_file, "r");
+ f = fopen(pid_file, "r");
if (f) {
if (fgets(buffer, sizeof(buffer), f)) {
pid = atoi(buffer);
s->qmp_fd = socket_accept(qmpsock);
s->rx = g_string_new("");
- s->pid_file = pid_file;
s->child_pid = pid;
for (i = 0; i < MAX_IRQ; i++) {
s->irq_level[i] = false;
qtest_qmp_discard_response(s, "");
qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+ s->qemu_pid = read_pid_file(pid_file);
+ unlink(pid_file);
+ g_free(pid_file);
+
if (getenv("QTEST_STOP")) {
- kill(qtest_qemu_pid(s), SIGSTOP);
+ kill(s->qemu_pid, SIGSTOP);
}
return s;
{
int status;
- pid_t pid = qtest_qemu_pid(s);
- if (pid != -1) {
- kill(pid, SIGTERM);
- waitpid(pid, &status, 0);
+ if (s->qemu_pid != -1) {
+ kill(s->qemu_pid, SIGTERM);
+ waitpid(s->qemu_pid, &status, 0);
}
close(s->fd);
close(s->qmp_fd);
g_string_free(s->rx, true);
- unlink(s->pid_file);
unlink(s->socket_path);
unlink(s->qmp_socket_path);
- g_free(s->pid_file);
g_free(s->socket_path);
g_free(s->qmp_socket_path);
g_free(s);