[libvirt RFCv4 04/20] runio: add arguments to extend use beyond just stdin and stdout

Daniel P. Berrangé berrange at redhat.com
Thu Apr 28 13:02:29 UTC 2022


On Thu, Apr 28, 2022 at 01:54:28PM +0100, Daniel P. Berrangé wrote:
> On Wed, Apr 27, 2022 at 11:13:23PM +0200, Claudio Fontana wrote:
> > add arguments to runio to allow read/write from/to arbitrary
> > file descriptors, as opposed to just stdin and stdout.
> > 
> > Signed-off-by: Claudio Fontana <cfontana at suse.de>
> > ---
> >  src/util/iohelper.c |  2 +-
> >  src/util/runio.c    | 10 +++++-----
> >  src/util/runio.h    | 17 ++++++++++++++++-
> >  3 files changed, 22 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/util/iohelper.c b/src/util/iohelper.c
> > index 5a0098542e..93674c1e2f 100644
> > --- a/src/util/iohelper.c
> > +++ b/src/util/iohelper.c
> > @@ -96,7 +96,7 @@ main(int argc, char **argv)
> >          usage(EXIT_FAILURE);
> >      }
> >  
> > -    if (fd < 0 || runIO(path, fd, oflags) < 0)
> > +    if (fd < 0 || runIO(path, fd, oflags, STDIN_FILENO, STDOUT_FILENO) < 0)
> >          goto error;
> >  
> >      return 0;
> > diff --git a/src/util/runio.c b/src/util/runio.c
> > index a7b902af7e..f42acddae9 100644
> > --- a/src/util/runio.c
> > +++ b/src/util/runio.c
> > @@ -134,7 +134,7 @@ runIOCopy(const struct runIOParams p)
> >  
> >  
> >  off_t
> > -runIO(const char *path, int fd, int oflags)
> > +runIO(const char *path, int fd, int oflags, int in_fd, int out_fd)
> 
> This is getting rather wierd as a signature.
> 
> If O_RDONLY, then in_fd is ignored, 'fd' is input.
> 
> If O_WRONLY, then out_fd is ignored, 'fd' is output
> 
> What about instead simply :
> 
>    runIO(const char *srcpath, int srcfd,
>          const char *dstpath, int dstfd)
> 
> so there's no read vs write distinction at all.

I guess we need 'int srcflags and 'int dstflags' too, unless we just
call fcntl() to query them instead.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


More information about the libvir-list mailing list