|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] scripts: Use stat to check lock claim
On Tue, Mar 10, 2020 at 4:06 PM Jason Andryuk <jandryuk@xxxxxxxxx> wrote:
>
> On Tue, Mar 10, 2020 at 11:43 AM Ian Jackson <ian.jackson@xxxxxxxxxx> wrote:
> > Alternatively, if you don't mind using --printf instead of -c,
> >
> > $ bash -c 'x=$( stat -L --format "%D.%i " t u 2>/dev/null || : ); echo
> > ${x%% *} = ${x#* }'
> > fe04.844307 = fe04.826417
> > $
> >
> > I don't know when --format was introduced.
>
> Looks like --printf was introduced in 2005. I think I prefer this to
> having the newlines. You still have some of the string substitution
> concerns, but I think think relying on a successful stat(1) call to
> give two output values is reasonable.
busybox stat does not support --printf. This is not an immediate
concern for me, but it's something I thought of and just tested. The
newline approach avoids this complication.
> > I'm sorry to bounce the patch over such a small thing, but this is
> > path is already quite slow and is critical for domain creation and I
> > would prefer not to add (two) additional subprocess invocations here.
>
> No worries.
The above gyrations can be avoided if we just call stat twice - once
for the fd and once for the file. They aren't required to be in a
single call. But moving forward with a single call, we have a few
options:
We could use an array to side-step the line splitting:
if stat=$( stat -L -c '%D.%i' - $_lockfile 0<&$_lockfd 2>/dev/null )
then
stat=(${stat})
fd_stat=${stat[0]}
file_stat=${stat[1]}
[ "$fd_stat" = "$file_stat" ]
Another option is to use the bashism $'\n' instead of the literal newlines:
if stat=$( stat -L -c '%D.%i' - $_lockfile 0<&$_lockfd 2>/dev/null )
then
fd_stat=${stat%$'\n'*}
file_stat=${stat#*$'\n'}
Or just use your newline construct. Which do you prefer?
Regards,
Jason
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |