qtest resource cleanup pull request
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJTBMPKAAoJEJykq7OBq3PIYWkIAJsWLbCVaG352bY4bdhssSbX H7IGS1eLYcJsZu6XLTh1KkesTJNhFzazG5XMagT8/5+Av9kkppnIs0K55G7qP+7R YZR4lA7fEIS7wQivKbh7mcFJjYYlHZRWBx3fmTxWQtn/S9B2bLAcZDuAkHv7oXHH ASCyFtbO23MJmAFBNUlqGU+DSGh0jCKyxJI2O3fgLlccgWkIdc0/5gaaLZbWpaKy HmKKKkp6rISlJRLSUyytjldaZhRuDkUCRa+9fKeHJkGzB1o0zN6MqSloVyhKc73y VrP1riHNOwecoZhpUs4t51/cogbrmuOWEydOwTLNbvtD5MGHGYblVWtY17OgibE= =rwDt -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanha/tags/qtest-monitor-process-pull-request' into staging qtest resource cleanup pull request # gpg: Signature made Wed 19 Feb 2014 14:46:34 GMT using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/qtest-monitor-process-pull-request: qtest: kill QEMU process on g_assert() failure qtest: make QEMU our direct child process qtest: drop unused child_pid field Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
3e890c77cf
@ -43,8 +43,8 @@ struct QTestState
|
||||
int qmp_fd;
|
||||
bool irq_level[MAX_IRQ];
|
||||
GString *rx;
|
||||
int child_pid; /* Child process created to execute QEMU */
|
||||
pid_t qemu_pid; /* QEMU process spawned by our child */
|
||||
pid_t qemu_pid; /* our child QEMU process */
|
||||
struct sigaction sigact_old; /* restored on exit */
|
||||
};
|
||||
|
||||
#define g_assert_no_errno(ret) do { \
|
||||
@ -89,20 +89,17 @@ static int socket_accept(int sock)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static pid_t read_pid_file(const char *pid_file)
|
||||
static void kill_qemu(QTestState *s)
|
||||
{
|
||||
FILE *f;
|
||||
char buffer[1024];
|
||||
pid_t pid = -1;
|
||||
|
||||
f = fopen(pid_file, "r");
|
||||
if (f) {
|
||||
if (fgets(buffer, sizeof(buffer), f)) {
|
||||
pid = atoi(buffer);
|
||||
}
|
||||
fclose(f);
|
||||
if (s->qemu_pid != -1) {
|
||||
kill(s->qemu_pid, SIGTERM);
|
||||
waitpid(s->qemu_pid, NULL, 0);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static void sigabrt_handler(int signo)
|
||||
{
|
||||
kill_qemu(global_qtest);
|
||||
}
|
||||
|
||||
QTestState *qtest_init(const char *extra_args)
|
||||
@ -111,10 +108,9 @@ QTestState *qtest_init(const char *extra_args)
|
||||
int sock, qmpsock, i;
|
||||
gchar *socket_path;
|
||||
gchar *qmp_socket_path;
|
||||
gchar *pid_file;
|
||||
gchar *command;
|
||||
const char *qemu_binary;
|
||||
pid_t pid;
|
||||
struct sigaction sigact;
|
||||
|
||||
qemu_binary = getenv("QTEST_QEMU_BINARY");
|
||||
g_assert(qemu_binary != NULL);
|
||||
@ -123,22 +119,28 @@ QTestState *qtest_init(const char *extra_args)
|
||||
|
||||
socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
|
||||
qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
|
||||
pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid());
|
||||
|
||||
sock = init_socket(socket_path);
|
||||
qmpsock = init_socket(qmp_socket_path);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
command = g_strdup_printf("%s "
|
||||
/* Catch SIGABRT to clean up on g_assert() failure */
|
||||
sigact = (struct sigaction){
|
||||
.sa_handler = sigabrt_handler,
|
||||
.sa_flags = SA_RESETHAND,
|
||||
};
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigaction(SIGABRT, &sigact, &s->sigact_old);
|
||||
|
||||
s->qemu_pid = fork();
|
||||
if (s->qemu_pid == 0) {
|
||||
command = g_strdup_printf("exec %s "
|
||||
"-qtest unix:%s,nowait "
|
||||
"-qtest-log /dev/null "
|
||||
"-qmp unix:%s,nowait "
|
||||
"-pidfile %s "
|
||||
"-machine accel=qtest "
|
||||
"-display none "
|
||||
"%s", qemu_binary, socket_path,
|
||||
qmp_socket_path, pid_file,
|
||||
qmp_socket_path,
|
||||
extra_args ?: "");
|
||||
execlp("/bin/sh", "sh", "-c", command, NULL);
|
||||
exit(1);
|
||||
@ -152,7 +154,6 @@ QTestState *qtest_init(const char *extra_args)
|
||||
g_free(qmp_socket_path);
|
||||
|
||||
s->rx = g_string_new("");
|
||||
s->child_pid = pid;
|
||||
for (i = 0; i < MAX_IRQ; i++) {
|
||||
s->irq_level[i] = false;
|
||||
}
|
||||
@ -161,10 +162,6 @@ QTestState *qtest_init(const char *extra_args)
|
||||
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(s->qemu_pid, SIGSTOP);
|
||||
}
|
||||
@ -174,13 +171,9 @@ QTestState *qtest_init(const char *extra_args)
|
||||
|
||||
void qtest_quit(QTestState *s)
|
||||
{
|
||||
int status;
|
||||
|
||||
if (s->qemu_pid != -1) {
|
||||
kill(s->qemu_pid, SIGTERM);
|
||||
waitpid(s->qemu_pid, &status, 0);
|
||||
}
|
||||
sigaction(SIGABRT, &s->sigact_old, NULL);
|
||||
|
||||
kill_qemu(s);
|
||||
close(s->fd);
|
||||
close(s->qmp_fd);
|
||||
g_string_free(s->rx, true);
|
||||
|
Loading…
Reference in New Issue
Block a user