Wednesday, January 16, 2013

Locking files in recorder

Sometimes you need to find out which recorded files are ready for processing and which are still being recorded. A new feature record_lock makes that possible.

recorder myrec {
record all;
record_interval 30s;
record_path /tmp/rec;
record_unique on;
record_lock on;

File being recorded is exclusively locked with fcntl lock engine. You can easily check file lock status from elsewhere. On FreeBSD you can use flock tool to check that. On Linux flock and fcntl are unrelated so you're left with writing a simple script. Here's an example of


import fcntl, sys

fcntl.lockf(open(sys.argv[1], "a"), fcntl.LOCK_EX|fcntl.LOCK_NB)

Use this script to check if file is currently being recorded.

for file in /tmp/rec/*; do
printf "$file : ";
if ~/ $file; then echo "ready"; else echo "locked"; fi;

No comments:

Post a Comment