how to test if a pipe contains data

Rich Felker dalias at aerifal.cx
Mon Jan 23 23:27:12 UTC 2012


On Tue, Jan 24, 2012 at 12:36:53AM +0100, Laurent Bercot wrote:
> > I need to transfer data coming from a pipe over a UMTS link to a web server.
> > From time to time, the UMTS link goes down, and worse, it sometimes cannot
> > be reestablished. I believe that in these cases, the firmware of the UMTS stick
> > hangs, but this is just a guess. Anyhow, the only way I could get the link up and
> > running again when this happens is to reboot the whole system.
> >
> > As my application will have tried for quite a while to get the link up
> > before such drastic measures, quite some data may have accumulated in the pipe.
> > To avoid loosing that data, I need to drain the pipe to store its data
> > to a file surviving the recovery. This is the place where I just want to check if
> > there is still data in the pipe. If it is empty, I reboot.
> 
>  I must be missing something obvious here. Why don't you just do things
> sequentially ?
> 
>  cat < namedpipe > savefile ; reboot

Note that all of these approaches have a nasty race condition where
new data might get written to the pipe (and lost) after it's saved..
You really should find a more robust, professional solution. Ugly
hacks like this are the reason so many embedded systems behave so
poorly.

Rich


More information about the busybox mailing list