qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Baron <jbaron@redhat.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com,
	qemu-devel@nongnu.org, andreas.faerber@web.de,
	pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/3] qtest: Enable creation of multiple qemu instances
Date: Thu, 20 Dec 2012 15:26:40 -0500	[thread overview]
Message-ID: <20121220202639.GA29647@redhat.com> (raw)
In-Reply-To: <CAAu8pHv6WM3R_y7yfRZ6mGJMjXDn+=pRchBzeJ5ztK2TyKU7Ug@mail.gmail.com>

On Thu, Dec 20, 2012 at 08:07:02PM +0000, Blue Swirl wrote:
> On Thu, Dec 20, 2012 at 5:14 PM, Jason Baron <jbaron@redhat.com> wrote:
> > From: Jason Baron <jbaron@redhat.com>
> >
> > Currently, the qtest harness can only spawn 1 qemu instance at a time because
> > the parent pid is used to create the socket files. Use 'mkdtemp()' in
> 
> But mkdtemp() is not available on Win32.

So this case important even for qtest?

> 
> > combination with the parent pid to avoid conflicts.
> >
> > Signed-off-by: Jason Baron <jbaron@redhat.com>
> > ---
> >  tests/libqtest.c |   15 +++++++++------
> >  1 files changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/tests/libqtest.c b/tests/libqtest.c
> > index 71b84c1..57665c9 100644
> > --- a/tests/libqtest.c
> > +++ b/tests/libqtest.c
> > @@ -41,6 +41,7 @@ struct QTestState
> >      GString *rx;
> >      gchar *pid_file;
> >      char *socket_path, *qmp_socket_path;
> > +    char *tmp_dir;
> >  };
> >
> >  #define g_assert_no_errno(ret) do { \
> > @@ -105,7 +106,6 @@ QTestState *qtest_init(const char *extra_args)
> >  {
> >      QTestState *s;
> >      int sock, qmpsock, ret, i;
> > -    gchar *pid_file;
> >      gchar *command;
> >      const char *qemu_binary;
> >      pid_t pid;
> > @@ -115,9 +115,11 @@ QTestState *qtest_init(const char *extra_args)
> >
> >      s = g_malloc(sizeof(*s));
> >
> > -    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());
> > +    s->tmp_dir = g_strdup_printf("/tmp/qtest-%d-XXXXXX", getpid());
> > +    g_assert(mkdtemp(s->tmp_dir) != NULL);
> > +    s->socket_path = g_strdup_printf("%s/%s", s->tmp_dir, "sock");
> > +    s->qmp_socket_path = g_strdup_printf("%s/%s", s->tmp_dir, "qmp");
> > +    s->pid_file = g_strdup_printf("%s/%s", s->tmp_dir, "pid");
> >
> >      sock = init_socket(s->socket_path);
> >      qmpsock = init_socket(s->qmp_socket_path);
> > @@ -131,7 +133,7 @@ QTestState *qtest_init(const char *extra_args)
> >                                    "-pidfile %s "
> >                                    "-machine accel=qtest "
> >                                    "%s", qemu_binary, s->socket_path,
> > -                                  s->qmp_socket_path, pid_file,
> > +                                  s->qmp_socket_path, s->pid_file,
> >                                    extra_args ?: "");
> >
> >          ret = system(command);
> > @@ -143,7 +145,6 @@ QTestState *qtest_init(const char *extra_args)
> >      s->qmp_fd = socket_accept(qmpsock);
> >
> >      s->rx = g_string_new("");
> > -    s->pid_file = pid_file;
> >      for (i = 0; i < MAX_IRQ; i++) {
> >          s->irq_level[i] = false;
> >      }
> > @@ -172,9 +173,11 @@ void qtest_quit(QTestState *s)
> >      unlink(s->pid_file);
> >      unlink(s->socket_path);
> >      unlink(s->qmp_socket_path);
> > +    unlink(s->tmp_dir);
> 
> -EISDIR, rmdir() would be needed instead.
> 

'unlink()' tested fine on Linux. But yes, it might not be as portable.

I looked at tempnam() and mktemp(), but they both generate linker warnings.
'mkstemp()' could be used but its awkward to delete the file right after
its created so that bind() can create it. Plus, it could be a greater
security risk in that the filename is easier to determine.

We could write our own random file string generator then, if mkdtemp(),
isn't ok.

> >      g_free(s->pid_file);
> >      g_free(s->socket_path);
> >      g_free(s->qmp_socket_path);
> > +    g_free(s->tmp_dir);
> >  }
> >
> >  static void socket_sendf(int fd, const char *fmt, va_list ap)
> > --
> > 1.7.1
> >

  reply	other threads:[~2012-12-20 20:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-20 17:14 [Qemu-devel] [PATCH v2 0/3] qtest: add migration testing Jason Baron
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 1/3] qtest: Enable creation of multiple qemu instances Jason Baron
2012-12-20 20:07   ` Blue Swirl
2012-12-20 20:26     ` Jason Baron [this message]
2012-12-20 20:38       ` Blue Swirl
2012-12-21  7:47       ` Markus Armbruster
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 3/3] qtest: add migrate-test Jason Baron
2012-12-20 20:17   ` Blue Swirl
2012-12-20 17:14 ` [Qemu-devel] [PATCH v2 2/3] qtest: extend qtest_qmp() to fill in the reply Jason Baron
2013-01-07 20:04   ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121220202639.GA29647@redhat.com \
    --to=jbaron@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=andreas.faerber@web.de \
    --cc=blauwirbel@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).