From: Chris Webb <chris@arachsys.com>
To: Javier Guerra Giraldez <javier@guerrag.com>
Cc: Freddie Cash <fjwcash@gmail.com>, kvm@vger.kernel.org
Subject: Re: qemu-send.c (was Re: Since we're sharing, here's my kvmctl script)
Date: Thu, 12 Jun 2008 09:35:23 +0100 [thread overview]
Message-ID: <20080612083523.GD8555@arachsys.com> (raw)
In-Reply-To: <200806112110.51553.javier@guerrag.com>
Javier Guerra Giraldez <javier@guerrag.com> writes:
> On Wednesday 11 June 2008, Chris Webb wrote:
> > Hi. I have a small 'qemu-send' utility for talking to a running qemu/kvm
> > process whose monitor console listens on a filesystem socket, which I think
> > might be a useful building block when extending these kinds of script to do
> > things like migratation, pausing, and so on. The source is attached.
>
> there's a utility called socat that let's you send text to/from TCP sockets
> and unix-domain sockets. it can even (temporarily) attach the terminal, or
> use GNU's readline to regain interactive control of KVM/Qemu
Hi. Yes, I'm aware of socat, netcat, tcpclient et al. and even have a
similar pair of little unix/tcp/udp/syslogging utilities myself called
sk/skd which I initially used for scripting our local kvm management system.
However, it's a little bit clumsy to use these tools correctly from a shell
script if you want to get back the command output intact. You need to open
your connection to the unix server socket, wait for the prompt (skipping the
welcome banner), send the command, copy the response out until you get a
line '(qemu) ', then disconnect. For the same reason you can't do
echo -e "GET / HTTP/1.1\n\n" >/dev/tcp/www.google.com/80
cat </dev/tcp/www.google.com/80
having to write
exec 3<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\n\n" >&3
cat <&3
instead, you need to avoid disconnecting from the socket in the middle of
the command/response exchange.
(In fact, with qemu, it nearly works anyway: the new connection gets all the
output and the next prompt from the old one before the new banner, so you
just have a couple of extra prompts, a command echo and a banner at the top
and bottom to filter away. However, I'd be very reluctant to rely on this
behaviour, and in particular on it not losing output between connections.
The method I implemented in qemu-send.c should be robust again changes in
the way qemu handles its monitor sockets.)
To get the convenient syntax and behaviour I wanted, it felt easier
and cleaner to write the few lines of C needed for a standalone utility
rather than introduce a parsing shell script/function plus a dependency on
one of sk/socat/netcat/tcpclient. I suspect also that I'm just more
comfortable in C than sh; YMMV!
Cheers,
Chris.
next prev parent reply other threads:[~2008-06-12 8:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 22:52 Since we're sharing, here's my kvmctl script Freddie Cash
2008-06-11 23:04 ` Freddie Cash
2008-06-12 15:15 ` Freddie Cash
2008-06-12 0:42 ` qemu-send.c (was Re: Since we're sharing, here's my kvmctl script) Chris Webb
2008-06-12 2:10 ` Javier Guerra Giraldez
2008-06-12 8:35 ` Chris Webb [this message]
2008-06-12 2:07 ` Since we're sharing, here's my kvmctl script Javier Guerra Giraldez
2008-06-12 8:38 ` William Boughton
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=20080612083523.GD8555@arachsys.com \
--to=chris@arachsys.com \
--cc=fjwcash@gmail.com \
--cc=javier@guerrag.com \
--cc=kvm@vger.kernel.org \
/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