qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] READCONFIG: Allow reading the configuration from a pre-existing filedescriptor
Date: Wed, 25 Jan 2012 15:47:27 -0700	[thread overview]
Message-ID: <4F20867F.3090705@redhat.com> (raw)
In-Reply-To: <1327530211-25614-2-git-send-email-ronniesahlberg@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2179 bytes --]

On 01/25/2012 03:23 PM, Ronnie Sahlberg wrote:
> Update the readconfig filename parsing to allow specifying an existing, inherited, filedescriptor as 'fd:<n>'
> This is useful when you want to pass potentially sensitive onfiguration data to qemu without having it hit the filesystem/stable-storage
> 
> Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
> ---
>  qemu-config.c   |   15 +++++++++++++--
>  qemu-options.hx |    3 ++-
>  2 files changed, 15 insertions(+), 3 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/qemu-config.c b/qemu-config.c
> index b030205..c12c5eb 100644
> --- a/qemu-config.c
> +++ b/qemu-config.c
> @@ -770,8 +770,19 @@ out:
>  
>  int qemu_read_config_file(const char *filename)
>  {
> -    FILE *f = fopen(filename, "r");
> -    int ret;
> +    FILE *f;
> +    int ret, fd;
> +
> +    if (strncmp(filename, "fd:", 3)) {
> +        f = fopen(filename, "r");
> +    } else {
> +        errno = 0;
> +        fd = strtol(filename + 3, NULL, 10);

This means

-readconfig fd:4junk

will read fd 4.  I don't know if there is a policy on ignoring vs.
rejecting ill-formed command line, which is why I'm okay with the patch
as-is if it meets project policy; but you might want to consider passing
a non-NULL pointer for the second argument and rejecting an empty string
or trailing junk.

> +        if (errno != 0) {
> +            return -errno;
> +        }

POSIX says that strtol("", NULL, 10) may return 0 without setting errno
(that is, you can't rely on EINVAL in that case).  That's another
argument for _always_ passing a non-NULL pointer and to see if you
accidentally parsed an empty string, since you don't want to have
another FILE* competing with stdin.  [Libvirt forbids the direct use of
strtol and friends, and instead provides wrapper functions that take
care of the sanity checking that is not mandated by POSIX; it may be
worth introducing a qemu_strtol that does likewise, but that's a
different cleanup project with wider scope.]

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

  reply	other threads:[~2012-01-25 22:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-25 22:23 [Qemu-devel] [PATCH 0/0] Allow -readconfig to read from a pre-existing filedescriptor Ronnie Sahlberg
2012-01-25 22:23 ` [Qemu-devel] [PATCH] READCONFIG: Allow reading the configuration " Ronnie Sahlberg
2012-01-25 22:47   ` Eric Blake [this message]
2012-01-26  7:40     ` Markus Armbruster
2012-01-26 10:43       ` Daniel P. Berrange
2012-03-08 19:13       ` Eduardo Habkost

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=4F20867F.3090705@redhat.com \
    --to=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.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).