Re: Output redirection to block-defined filehandle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Langhoff <martin.langhoff@xxxxxxxxx> wrote:
> The flock binary in modern linuxes (from util-linux-ng) supports
> flocking a filehandle that is handled by the shell. Combining this
> with per-code-block filehandles / io redirection, it is an incredibly
> useful construct to protect a code block with a lock.
> 
> The resulting code looks like this (from man flock on Fedora 11):
> 
>      (
>         flock -s 200
>         # ... commands executed under lock ...
>       ) 200>/var/lock/mylockfile
> 
> I am now discovering that this works in bash, but not in dash.
> 
> Is there a posixly correct way to do this? Can dash handle it? Is
> there a syntax for this that is both dash and bash friendly?
> 
> If the answer is not -- this codepath is conditional. Is there a way
> for me to test for which shell is running (and only attempt it under
> bash)?

POSIX only requires file descriptors 0-9 for shell redirections.
So if you replace 200 with 9 it should work assuming that nothing
within the block uses fd 9.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux