[Libguestfs] [PATCH nbdkit 1/2] file: Add an internal "mode"

Richard W.M. Jones rjones at redhat.com
Thu Aug 18 10:33:03 UTC 2022


On Thu, Aug 18, 2022 at 12:30:21PM +0200, Laszlo Ersek wrote:
> On 08/18/22 11:53, Richard W.M. Jones wrote:
> > 
> > This is upstream in 5 commits 5764fa6f4..dd28b0054:
> > 
> > https://gitlab.com/nbdkit/nbdkit/-/commit/2620d95a4585204f0db0d55c0d41276d11970436
> > https://gitlab.com/nbdkit/nbdkit/-/commit/185e7d4010b353f36b5ca5d47467a770c530e58c
> > https://gitlab.com/nbdkit/nbdkit/-/commit/17655b1ca67caa454e7a4ac83bc8c052b79a692d
> > https://gitlab.com/nbdkit/nbdkit/-/commit/e7fdffde8142fb083625678b7a55455751185502
> > https://gitlab.com/nbdkit/nbdkit/-/commit/dd28b005430d020ccd1825437937c317332d3007
> > 
> > This also includes dirfd functionality and a rather complicated test
> > for that.  Turns out that bash refuses to open a directory as a file
> > descriptor :-(
> 
> This doesn't match my experience; for me, bash opens e.g. /tmp just fine
> on both RHEL7 and Fedora35 -- but it must be a read-only open.
> 
> $ exec 9</tmp
> [ok]

Hmmm, that makes sense since we don't even need to write to the
directory.  Let's see if I can simplify that test ...

> $ exec 9<>/tmp
> bash: /tmp: Is a directory
> 
> The latter is actually expected; it comes from open(). See EISDIR at
> <https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html>.
> 
> Commit dd28b005430d also adds
> 
>   dfd = open (tmpdir, O_RDONLY | O_DIRECTORY);
> 
> where I think O_DIRECTORY is not strictly necessary (per spec, because
> O_CREAT is absent, O_DIRECTORY only helps us refuse a non-directory --
> but we do not expect such "attacks" here). So my take is that
> O_DIRECTORY could be dropped from the C code, at which point a bash
> redirection (read-only) should work just the same.
> 
> Laszlo

Rich.


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org


More information about the Libguestfs mailing list