Patchwork [05/32] qtest: Tidy up temporary files properly

login
register
mail settings
Submitter Markus Armbruster
Date July 6, 2012, 6:57 a.m.
Message ID <1341557890-17464-6-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/169383/
State New
Headers show

Comments

Markus Armbruster - July 6, 2012, 6:57 a.m.
Each test litters /tmp with several files: a pid file and two
sockets.  Tidy up.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/libqtest.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)
Blue Swirl - July 7, 2012, 7:39 a.m.
On Fri, Jul 6, 2012 at 6:57 AM, Markus Armbruster <armbru@redhat.com> wrote:
> Each test litters /tmp with several files: a pid file and two
> sockets.  Tidy up.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

While a nice patch, I don't think it should belong to this series.

> ---
>  tests/libqtest.c |   29 ++++++++++++++++-------------
>  1 files changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 071b6be..02d0392 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -40,6 +40,7 @@ struct QTestState
>      bool irq_level[MAX_IRQ];
>      GString *rx;
>      gchar *pid_file;
> +    char *socket_path, *qmp_socket_path;
>  };
>
>  #define g_assert_no_errno(ret) do { \
> @@ -88,8 +89,6 @@ QTestState *qtest_init(const char *extra_args)
>  {
>      QTestState *s;
>      int sock, qmpsock, ret, i;
> -    gchar *socket_path;
> -    gchar *qmp_socket_path;
>      gchar *pid_file;
>      gchar *command;
>      const char *qemu_binary;
> @@ -98,14 +97,14 @@ QTestState *qtest_init(const char *extra_args)
>      qemu_binary = getenv("QTEST_QEMU_BINARY");
>      g_assert(qemu_binary != NULL);
>
> -    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());
> -
>      s = g_malloc(sizeof(*s));
>
> -    sock = init_socket(socket_path);
> -    qmpsock = init_socket(qmp_socket_path);
> +    s->socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
> +    s->qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
> +    pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid());
> +
> +    sock = init_socket(s->socket_path);
> +    qmpsock = init_socket(s->qmp_socket_path);
>
>      pid = fork();
>      if (pid == 0) {
> @@ -115,8 +114,8 @@ QTestState *qtest_init(const char *extra_args)
>                                    "-qmp unix:%s,nowait "
>                                    "-pidfile %s "
>                                    "-machine accel=qtest "
> -                                  "%s", qemu_binary, socket_path,
> -                                  qmp_socket_path, pid_file,
> +                                  "%s", qemu_binary, s->socket_path,
> +                                  s->qmp_socket_path, pid_file,
>                                    extra_args ?: "");
>
>          ret = system(command);
> @@ -133,9 +132,6 @@ QTestState *qtest_init(const char *extra_args)
>          s->irq_level[i] = false;
>      }
>
> -    g_free(socket_path);
> -    g_free(qmp_socket_path);
> -
>      /* Read the QMP greeting and then do the handshake */
>      qtest_qmp(s, "");
>      qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
> @@ -160,6 +156,13 @@ void qtest_quit(QTestState *s)
>
>          fclose(f);
>      }
> +
> +    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);
>  }
>
>  static void socket_sendf(int fd, const char *fmt, va_list ap)
> --
> 1.7.6.5
>
Markus Armbruster - July 9, 2012, 7:56 a.m.
Blue Swirl <blauwirbel@gmail.com> writes:

> On Fri, Jul 6, 2012 at 6:57 AM, Markus Armbruster <armbru@redhat.com> wrote:
>> Each test litters /tmp with several files: a pid file and two
>> sockets.  Tidy up.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> While a nice patch, I don't think it should belong to this series.

Understand, but what do you want me to do?  I could repost this series
without this patch, and post the patch separately, but that feels like
busywork.
Kevin Wolf - July 9, 2012, 9:09 a.m.
Am 09.07.2012 09:56, schrieb Markus Armbruster:
> Blue Swirl <blauwirbel@gmail.com> writes:
> 
>> On Fri, Jul 6, 2012 at 6:57 AM, Markus Armbruster <armbru@redhat.com> wrote:
>>> Each test litters /tmp with several files: a pid file and two
>>> sockets.  Tidy up.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>
>> While a nice patch, I don't think it should belong to this series.
> 
> Understand, but what do you want me to do?  I could repost this series
> without this patch, and post the patch separately, but that feels like
> busywork.

I have already picked up some patches including this, so I will include
it in a possible pull request before the whole series is merged.
Resending separately wouldn't change much, except maybe that another
maintainer would pick it up.

Kevin

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 071b6be..02d0392 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -40,6 +40,7 @@  struct QTestState
     bool irq_level[MAX_IRQ];
     GString *rx;
     gchar *pid_file;
+    char *socket_path, *qmp_socket_path;
 };
 
 #define g_assert_no_errno(ret) do { \
@@ -88,8 +89,6 @@  QTestState *qtest_init(const char *extra_args)
 {
     QTestState *s;
     int sock, qmpsock, ret, i;
-    gchar *socket_path;
-    gchar *qmp_socket_path;
     gchar *pid_file;
     gchar *command;
     const char *qemu_binary;
@@ -98,14 +97,14 @@  QTestState *qtest_init(const char *extra_args)
     qemu_binary = getenv("QTEST_QEMU_BINARY");
     g_assert(qemu_binary != NULL);
 
-    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());
-
     s = g_malloc(sizeof(*s));
 
-    sock = init_socket(socket_path);
-    qmpsock = init_socket(qmp_socket_path);
+    s->socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
+    s->qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
+    pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid());
+
+    sock = init_socket(s->socket_path);
+    qmpsock = init_socket(s->qmp_socket_path);
 
     pid = fork();
     if (pid == 0) {
@@ -115,8 +114,8 @@  QTestState *qtest_init(const char *extra_args)
                                   "-qmp unix:%s,nowait "
                                   "-pidfile %s "
                                   "-machine accel=qtest "
-                                  "%s", qemu_binary, socket_path,
-                                  qmp_socket_path, pid_file,
+                                  "%s", qemu_binary, s->socket_path,
+                                  s->qmp_socket_path, pid_file,
                                   extra_args ?: "");
 
         ret = system(command);
@@ -133,9 +132,6 @@  QTestState *qtest_init(const char *extra_args)
         s->irq_level[i] = false;
     }
 
-    g_free(socket_path);
-    g_free(qmp_socket_path);
-
     /* Read the QMP greeting and then do the handshake */
     qtest_qmp(s, "");
     qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
@@ -160,6 +156,13 @@  void qtest_quit(QTestState *s)
 
         fclose(f);
     }
+
+    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);
 }
 
 static void socket_sendf(int fd, const char *fmt, va_list ap)