[lug] how to handle open files - upload server
rm at fabula.de
rm at fabula.de
Wed Jan 14 03:58:08 MST 2004
On Tue, Jan 13, 2004 at 06:05:17PM -0800, vlad wrote:
> Hello. First post here, but I thought I'd throw in my two cents:
> 1. I've had problems with locking libs in earlier versions of Linux.
> Can't remember if it was flock or fcntl, but I'd check out the problems
> with each if you're running around RH 7.2-7.3.
both are in libc and used in rather critical applications. What exactly
where the problems?
> 2. The answer to everything is Perl ;) If this works, test the
> modification time on it and if it's within a threshhold, move it. Wait
> a moment, then test again.
Wide open to all sorts of race condition. Modification time won't tell
you anything about the current users of the file. Example: a remote
client opens the file for transfer, then the TCP connection stalls
(cleaning woman pulled the network plug), your program starts reading
the data and the remote program comes up again and changes the files
_content_ while you process the data ...
Perl has bindings for both flock and fcntl with good reasons ;-)
> eg: perl -e 'print (time-(stat("/var/log/maillog")));'
> .. will display the seconds since that file was last modified. Of
> course you'll have to think about syslogd caching something, but if
> you're not sending a rocket to the mars, this may work for you.
Phrases like "may work" or "most likely"/"most of the time" make me
shudder. And one lesson i learned as a programmer: never think you
know for shure what your customer does with your software -- what might
be todays quick hack might end up as a critical part of software
Just my 0.02E
> Bear Giles wrote:
> >rm at fabula.de wrote:
> >> A _big_ caveat: all these techniques use non-atomic operations and
> >> hence are vulnerable to race conditions (well, i'm not shure about
> >> exclusive locking allone, i'd have to look it up).
> >Locking is handled in the kernel, so atomic operation shouldn't be a
> >As for whether the files are locked, check
> >/usr/src/linux/Documentation/locks.txt and mandatory.txt. The OP may
> >need to mount the incoming directory with some special mount flags,
> >but he should be using a dedicated partition anyway to prevent a DOS
> >attack by somebody sftp'ing /dev/null at him. :-)
> >Web Page: http://lug.boulder.co.us
> >Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> >Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
More information about the LUG