On Thu, Jan 07, 2016 at 07:43:32AM +0100, Bastian Bittorf wrote:
> I'am trying to use flock on OpenWrt with musl and
> busybox-git/HEAD. What happens here is this:
> 
> root@OpenWrt:/ flock test
> flock: invalid number 'test'
<snip>
> root@OpenWrt:/ flock
> BusyBox v1.25.0.git (2016-01-06 23:08:01 CET) 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
> 
> so what is the expected usage?

If you read the help closer, you will see that it's
flock FD
*OR*
flock FILE [-c] PROG ARGS

You cannot meaningfully flock a filename without spawning a program:
it would open the file, lock it, and close it, destroying the lock.

If you want to run it to lock a critical section of a script, use
exec FD>> FILE
flock FD
...
flock -u FD

(I'm not sure offhand whether you need spaces between FD and the
redirection; < > >> <> are all possible redirectors, meaning open
RO/WO/APPEND/RW.)

HTH,
Isaac Dunham
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to