All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Andryuk <jandryuk@gmail.com>
To: Ian Jackson <ian.jackson@citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>, Wei Liu <wl@xen.org>,
	Paul Durrant <paul@xen.org>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	Elliott Mitchell <ehem+xen@m5p.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [XEN RFC for-4.14] Re: use of "stat -"
Date: Wed, 24 Jun 2020 22:37:59 -0400	[thread overview]
Message-ID: <CAKf6xpvLrXkBR6okFQ9u=9GfN-h_XHeLtwQV9pBRRAFXmbwVsQ@mail.gmail.com> (raw)
In-Reply-To: <24307.32018.502303.817846@mariner.uk.xensource.com>

On Wed, Jun 24, 2020 at 12:19 PM Ian Jackson <ian.jackson@citrix.com> wrote:
>
> Jan Beulich writes ("Re: use of "stat -""):
> > [CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.
> > On 14.05.2020 13:02, Ian Jackson wrote:
> > > I've read this thread.  Jan, I'm sorry that this causes you
> > > inconvenience.  I'm hoping it won't come down to a choice between
> > > supporting people who want to ship a dom0 without perl, and people who
> > > want a dom0 using more-than-a-decade-old coreutils.
> > >
> > > Jan, can you tell me what the output is of this on your ancient
> > > system:
> > >
> > >   $ rm -f t
> > >   $ >t
> > >   $ exec 3<t
> > >   $ stat -L -c '%F %i' /dev/stdin <&3
> > >   regular empty file 393549
> > >   $ rm t
> > >   $ stat -L -c '%F %i' /dev/stdin <&3
> > >   regular empty file 393549
> > >   $ strace -ou stat -L -c '%F %i' /dev/stdin <&3
> > >   $
> >
> > $ rm -f t
> > $ >t
> > $ exec 3<t
> > $ stat -L -c '%F %i' /dev/stdin <&3
> > regular empty file 3380369
> > $ rm t
> > $ stat -L -c '%F %i' /dev/stdin <&3
> > regular empty file 3380369
> > $ strace -ou stat -L -c '%F %i' /dev/stdin <&3
> > regular empty file 3380369
> >
> > > Also, the contents of the file "u" afterwards, please.
> >
> > Attached.
>
> Thanks.
>
> I think this means that `stat -' can be replaced by `stat /dev/stdin'.
>
> This script is only run on Linux where /dev/stdin has existed
> basically forever.  The strace output shows
>   stat("/dev/stdin", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> and the transcript shows that your stat(1) behaves as I hope.
>
> Jan, will you send a patch ?  It is best if someone else but me writes
> it and tests it because then I am a "clean" reviewer.
>
> Paul, supposing I review such a patch and say it is low risk, and we
> commit it by Friday, can it have a release-ack ?

I was going to just write a patch to replace - with /dev/stdin and ask
Jan to test it.  When I opened the script, this comment was staring at
me:
        # We can't just stat /dev/stdin or /proc/self/fd/$_lockfd or
        # use bash's test -ef because those all go through what is
        # actually a synthetic symlink in /proc and we aren't
        # guaranteed that our stat(2) won't lose the race with an
        # rm(1) between reading the synthetic link and traversing the
        # file system to find the inum.

On my system:
$ ls -l /dev/stdin
lrwxrwxrwx 1 root root 15 Jun 24 21:13 /dev/stdin -> /proc/self/fd/0
$ ls -l /proc/self/fd/0 0<lockfile
lrwx------ 1 jason jason 64 Jun 24 21:26 /proc/self/fd/0 -> /home/jason/lockfile

stat /dev/stdin will work around the lack of `stat -` support, but it
doesn't address the race in the comment.  Is the comment valid?  How
would we prove there is no race for /dev/stdin?  And as a refresher,
`stat -` does an fstat(0), so there is no symlink lookup.  Or is there
no race since `stat /proc/self/fd/0` isn't a symlink lookup but just
accessing the already open fd via the proc special file? i.e.
equivalent to fstat.

I've mentioned it before, but maybe we should just use the Qubes
patch.  It leaves the lockfile even when no-one is holding the lock,
but it simplifies the code and sidesteps the issues we are discussing
here.
https://github.com/QubesOS/qubes-vmm-xen/blob/xen-4.13/patch-tools-hotplug-drop-perl-usage-in-locking-mechanism.patch

Regards,
Jason


  reply	other threads:[~2020-06-25  2:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 10:58 use of "stat -" Jan Beulich
2020-05-12 14:19 ` Wei Liu
2020-05-12 14:33   ` Jan Beulich
2020-05-12 14:47     ` Andrew Cooper
2020-05-12 14:59       ` Jan Beulich
2020-05-12 15:52         ` Jason Andryuk
2020-05-12 19:50           ` Elliott Mitchell
2020-05-12 19:54             ` Andrew Cooper
2020-05-12 22:54               ` Elliott Mitchell
2020-05-14 11:02                 ` Ian Jackson
2020-05-14 12:39                   ` Jan Beulich
2020-05-18 10:34                   ` Jan Beulich
2020-06-24 15:55                     ` Ping: " Jan Beulich
2020-06-24 16:19                     ` [XEN RFC for-4.14] " Ian Jackson
2020-06-25  2:37                       ` Jason Andryuk [this message]
2020-06-25  7:05                         ` Jan Beulich
2020-06-25 12:04                           ` Jason Andryuk
2020-06-25 13:31                           ` Ian Jackson
2020-06-25 13:48                             ` Jan Beulich
2020-06-25 14:16                               ` Jason Andryuk
2020-06-25  7:27                         ` Rich Persaud
2020-06-25 13:27                         ` Ian Jackson
2020-06-25 14:08                           ` Jan Beulich
2020-06-25 14:18                             ` Jason Andryuk
2020-06-25 14:37                               ` Ian Jackson
2020-06-25 14:19                             ` Ian Jackson
2020-06-25  7:03                       ` Paul Durrant

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='CAKf6xpvLrXkBR6okFQ9u=9GfN-h_XHeLtwQV9pBRRAFXmbwVsQ@mail.gmail.com' \
    --to=jandryuk@gmail.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=ehem+xen@m5p.com \
    --cc=ian.jackson@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=paul@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.