diff mbox series

[nfs-utils] start-statd: use flock -x instead of -e for busybox compatibility

Message ID 20240228185644.2743036-1-a.fatoum@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series [nfs-utils] start-statd: use flock -x instead of -e for busybox compatibility | expand

Commit Message

Ahmad Fatoum Feb. 28, 2024, 6:56 p.m. UTC
busybox flock(1) only supports -x and not -e. util-linux flock(1)
treats both -e and -x the same, documents them both in its man page,
but lists only -x in its help output.

Referring to util-linux git, it seems both options were added between
util-linux-2.13-pre1 and util-linux-2.13-pre2 back in 2006, so there
should be no harm in switching over to flock -x to avoid confusing
error output when attempting to mount a NFS on a busybox system:

  $ mount -t nfs 192.168.2.13:/home/afa/nfsroot/imx8mn-evk /mnt
  flock: invalid option -- 'e'
  BusyBox v1.36.0 () multi-call binary.

  Usage: flock [-sxun] FD | { FILE [-c] PROG ARGS }

  [Un]lock file descriptor, or lock FILE, run PROG

          -s      Shared lock
          -x      Exclusive lock (default)
          -u      Unlock FD
          -n      Fail rather than wait

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 utils/statd/start-statd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Calum Mackay Feb. 28, 2024, 9:09 p.m. UTC | #1
On 28/02/2024 6:56 pm, Ahmad Fatoum wrote:
> busybox flock(1) only supports -x and not -e. util-linux flock(1)
> treats both -e and -x the same, documents them both in its man page,
> but lists only -x in its help output.
> 
> Referring to util-linux git, it seems both options were added between
> util-linux-2.13-pre1 and util-linux-2.13-pre2 back in 2006, so there
> should be no harm in switching over to flock -x to avoid confusing
> error output when attempting to mount a NFS on a busybox system:
> 
>    $ mount -t nfs 192.168.2.13:/home/afa/nfsroot/imx8mn-evk /mnt
>    flock: invalid option -- 'e'
>    BusyBox v1.36.0 () multi-call binary.
> 
>    Usage: flock [-sxun] FD | { FILE [-c] PROG ARGS }
> 
>    [Un]lock file descriptor, or lock FILE, run PROG
> 
>            -s      Shared lock
>            -x      Exclusive lock (default)
>            -u      Unlock FD
>            -n      Fail rather than wait
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

hi Ahmad,

Since the default is an exclusive lock, in both BusyBox and util-linux, 
might it be simpler just to run flock without that option?

best wishes,
calum.

> ---
>   utils/statd/start-statd | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utils/statd/start-statd b/utils/statd/start-statd
> index b11a7d91a7f6..67a2f4ad8e0e 100755
> --- a/utils/statd/start-statd
> +++ b/utils/statd/start-statd
> @@ -8,7 +8,7 @@ PATH="/sbin:/usr/sbin:/bin:/usr/bin"
>   
>   # Use flock to serialize the running of this script
>   exec 9> /run/rpc.statd.lock
> -flock -e 9
> +flock -x 9
>   
>   if [ -s /run/rpc.statd.pid ] &&
>          [ "1$(cat /run/rpc.statd.pid)" -gt 1 ] &&
Ahmad Fatoum Feb. 29, 2024, 10:38 a.m. UTC | #2
Hello Calum,

On 28.02.24 22:09, Calum Mackay wrote:
> On 28/02/2024 6:56 pm, Ahmad Fatoum wrote:
>> busybox flock(1) only supports -x and not -e. util-linux flock(1)
>> treats both -e and -x the same, documents them both in its man page,
>> but lists only -x in its help output.
>>
>> Referring to util-linux git, it seems both options were added between
>> util-linux-2.13-pre1 and util-linux-2.13-pre2 back in 2006, so there
>> should be no harm in switching over to flock -x to avoid confusing
>> error output when attempting to mount a NFS on a busybox system:
>>
>>    $ mount -t nfs 192.168.2.13:/home/afa/nfsroot/imx8mn-evk /mnt
>>    flock: invalid option -- 'e'
>>    BusyBox v1.36.0 () multi-call binary.
>>
>>    Usage: flock [-sxun] FD | { FILE [-c] PROG ARGS }
>>
>>    [Un]lock file descriptor, or lock FILE, run PROG
>>
>>            -s      Shared lock
>>            -x      Exclusive lock (default)
>>            -u      Unlock FD
>>            -n      Fail rather than wait
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> hi Ahmad,
> 
> Since the default is an exclusive lock, in both BusyBox and util-linux, might it be simpler just to run flock without that option?

That would be another possibility, yes. I don't mind the explicitness in
specifying an argument, but I don't feel strongly either way.

Cheers,
Ahmad

> 
> best wishes,
> calum.
> 
>> ---
>>   utils/statd/start-statd | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/utils/statd/start-statd b/utils/statd/start-statd
>> index b11a7d91a7f6..67a2f4ad8e0e 100755
>> --- a/utils/statd/start-statd
>> +++ b/utils/statd/start-statd
>> @@ -8,7 +8,7 @@ PATH="/sbin:/usr/sbin:/bin:/usr/bin"
>>     # Use flock to serialize the running of this script
>>   exec 9> /run/rpc.statd.lock
>> -flock -e 9
>> +flock -x 9
>>     if [ -s /run/rpc.statd.pid ] &&
>>          [ "1$(cat /run/rpc.statd.pid)" -gt 1 ] &&
> 
>
Steve Dickson March 15, 2024, 1:11 p.m. UTC | #3
On 2/28/24 1:56 PM, Ahmad Fatoum wrote:
> busybox flock(1) only supports -x and not -e. util-linux flock(1)
> treats both -e and -x the same, documents them both in its man page,
> but lists only -x in its help output.
> 
> Referring to util-linux git, it seems both options were added between
> util-linux-2.13-pre1 and util-linux-2.13-pre2 back in 2006, so there
> should be no harm in switching over to flock -x to avoid confusing
> error output when attempting to mount a NFS on a busybox system:
> 
>    $ mount -t nfs 192.168.2.13:/home/afa/nfsroot/imx8mn-evk /mnt
>    flock: invalid option -- 'e'
>    BusyBox v1.36.0 () multi-call binary.
> 
>    Usage: flock [-sxun] FD | { FILE [-c] PROG ARGS }
> 
>    [Un]lock file descriptor, or lock FILE, run PROG
> 
>            -s      Shared lock
>            -x      Exclusive lock (default)
>            -u      Unlock FD
>            -n      Fail rather than wait
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Committed... (tag  nfs-utils-2-7-1-rc5)

I like that fact the lock is explicitly
set... takes out the guess work.

steved.
> ---
>   utils/statd/start-statd | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utils/statd/start-statd b/utils/statd/start-statd
> index b11a7d91a7f6..67a2f4ad8e0e 100755
> --- a/utils/statd/start-statd
> +++ b/utils/statd/start-statd
> @@ -8,7 +8,7 @@ PATH="/sbin:/usr/sbin:/bin:/usr/bin"
>   
>   # Use flock to serialize the running of this script
>   exec 9> /run/rpc.statd.lock
> -flock -e 9
> +flock -x 9
>   
>   if [ -s /run/rpc.statd.pid ] &&
>          [ "1$(cat /run/rpc.statd.pid)" -gt 1 ] &&
diff mbox series

Patch

diff --git a/utils/statd/start-statd b/utils/statd/start-statd
index b11a7d91a7f6..67a2f4ad8e0e 100755
--- a/utils/statd/start-statd
+++ b/utils/statd/start-statd
@@ -8,7 +8,7 @@  PATH="/sbin:/usr/sbin:/bin:/usr/bin"
 
 # Use flock to serialize the running of this script
 exec 9> /run/rpc.statd.lock
-flock -e 9
+flock -x 9
 
 if [ -s /run/rpc.statd.pid ] &&
        [ "1$(cat /run/rpc.statd.pid)" -gt 1 ] &&