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 <ronniesahlb...@gmail.com> > --- > qemu-config.c | 15 +++++++++++++-- > qemu-options.hx | 3 ++- > 2 files changed, 15 insertions(+), 3 deletions(-)
Reviewed-by: Eric Blake <ebl...@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 ebl...@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature