Skip to contentSkip to conversation

qtest: Unlink pid file before reading from QMP

PATCH In review Andreas Färber 2 participants 4 messages Feb 9, 2014 – Feb 17, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qtest: Unlink pid file before reading from QMP

Despite 1ad3c6abc0d67e00b84abaa5527bc64b70ca2205, supplying invalid arguments to the QEMU process still leaked a /tmp/qtest-*.pid file.

Fix this by reordering the reading and unlinking to before reading from QMP socket, which relies on a running process.

---
 tests/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/libqtest.c +4 -4
index c9a4f89..9433782 100644
@@ -157,14 +157,14 @@ QTestState *qtest_init(const char *extra_args)
         s->irq_level[i] = false;
     }
 
-    /* Read the QMP greeting and then do the handshake */
-    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);
 
+    /* Read the QMP greeting and then do the handshake */
+    qtest_qmp_discard_response(s, "");
+    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+
     if (getenv("QTEST_STOP")) {
         kill(s->qemu_pid, SIGSTOP);
     }
Signature · 1 line
1.8.4.5
#1 lore raw
Quoted 22 lines · Andreas Färber

Despite 1ad3c6abc0d67e00b84abaa5527bc64b70ca2205, supplying invalid arguments to the QEMU process still leaked a /tmp/qtest-*.pid file.

Fix this by reordering the reading and unlinking to before reading from QMP socket, which relies on a running process.

---
 tests/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/libqtest.c +0 -2
index c9a4f89..9433782 100644
@@ -157,14 +157,14 @@ QTestState *qtest_init(const char *extra_args)
         s->irq_level[i] = false;
     }
 
-    /* Read the QMP greeting and then do the handshake */
-    qtest_qmp_discard_response(s, "");

tests/libqtest.c QTestState *qtest_init(const char *extra_args) · line 167

Quoted 10 lines
tests/libqtest.c +4 -2
-    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
-
     s->qemu_pid = read_pid_file(pid_file);
     unlink(pid_file);
     g_free(pid_file);
 
+    /* Read the QMP greeting and then do the handshake */
+    qtest_qmp_discard_response(s, "");
+    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+

Hmm...the original ordering was intentional.

In order to avoid race conditions between QEMU creating the pid file and qtest reading the pid file, we wait until socket communication with QEMU has been performed. That way we're sure the pid file already exists.

I think the tests can now fail due to the race condition.

Stefan

#2 lore raw

Am 14.02.2014 15:43, schrieb Stefan Hajnoczi:

Quoted 36 lines · Andreas Färber
Quoted 22 lines

Despite 1ad3c6abc0d67e00b84abaa5527bc64b70ca2205, supplying invalid arguments to the QEMU process still leaked a /tmp/qtest-*.pid file.

Fix this by reordering the reading and unlinking to before reading from QMP socket, which relies on a running process.

---
 tests/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/libqtest.c +0 -2
index c9a4f89..9433782 100644
@@ -157,14 +157,14 @@ QTestState *qtest_init(const char *extra_args)
         s->irq_level[i] = false;
     }
 
-    /* Read the QMP greeting and then do the handshake */
-    qtest_qmp_discard_response(s, "");

tests/libqtest.c QTestState *qtest_init(const char *extra_args) · line 167

Quoted 10 lines
tests/libqtest.c +4 -2
-    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
-
     s->qemu_pid = read_pid_file(pid_file);
     unlink(pid_file);
     g_free(pid_file);
 
+    /* Read the QMP greeting and then do the handshake */
+    qtest_qmp_discard_response(s, "");
+    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+

Hmm...the original ordering was intentional.

Quoted 5 lines

In order to avoid race conditions between QEMU creating the pid file and qtest reading the pid file, we wait until socket communication with QEMU has been performed. That way we're sure the pid file already exists.

I think the tests can now fail due to the race condition.

I just verified that this patch did not slip into my pull. :)

Can you please propose an alternative solution or patch?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 41 lines · Andreas Färber

Am 14.02.2014 15:43, schrieb Stefan Hajnoczi:

Quoted 40 lines · Andreas Färber
Quoted 22 lines

Despite 1ad3c6abc0d67e00b84abaa5527bc64b70ca2205, supplying invalid arguments to the QEMU process still leaked a /tmp/qtest-*.pid file.

Fix this by reordering the reading and unlinking to before reading from QMP socket, which relies on a running process.

---
 tests/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/libqtest.c +0 -2
index c9a4f89..9433782 100644
@@ -157,14 +157,14 @@ QTestState *qtest_init(const char *extra_args)
         s->irq_level[i] = false;
     }
 
-    /* Read the QMP greeting and then do the handshake */
-    qtest_qmp_discard_response(s, "");

tests/libqtest.c QTestState *qtest_init(const char *extra_args) · line 167

Quoted 10 lines
tests/libqtest.c +4 -2
-    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
-
     s->qemu_pid = read_pid_file(pid_file);
     unlink(pid_file);
     g_free(pid_file);
 
+    /* Read the QMP greeting and then do the handshake */
+    qtest_qmp_discard_response(s, "");
+    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+

Hmm...the original ordering was intentional.

In order to avoid race conditions between QEMU creating the pid file and qtest reading the pid file, we wait until socket communication with QEMU has been performed. That way we're sure the pid file already exists.

Quoted 5 lines
Quoted 1 line

I think the tests can now fail due to the race condition.

I just verified that this patch did not slip into my pull. :)

Can you please propose an alternative solution or patch?

I have an idea to get rid of the pid file entirely. Will send a patch.

Stefan