[mythtv] mytharchive lock file issues

Paul Harrison mythtv at dsl.pipex.com
Mon Mar 5 23:01:51 UTC 2007

D. Hugh Redelmeier wrote:
> [Perhaps this should be a trac ticket, but I cannot seem to create one.]
> mytharchive has been acting up on me, so I did some investigation.
> Sometimes a mythburn step fails (I'm vague on how or what), leaving the 
> mythburn.lck lock file but no mythburn.py process.  When this happens,
> cancel requests are ineffective, and any attempt to archive something
> just gets you into the logviewer program, whatching the log make no
> further process.  Nothing will ever delete the lock.
> For example, we tried to put too much on a DVD and got into that
> state.
> So there are two problems:
> (1) a failure with no proper diagnostic or termination
> (2) and then no way to archive after this.
> This message was prompted by investigation of problem 2.
> I'm not the only one to have experienced this.  See, for example
> http://threebit.net/mail-archive/mythtv-users/msg35922.html
> The mythburn.lck lockfile logic in mythburn.py has a few problems.
> - The checking for and creation of a lock ought to be "atomic".
>   Otherwise there can be a race condition.  The conventional way of
>   doing this on UNIX-like systems is to try to creat a lockfile
>   using, in Python terms,
>   	os.open(lockfilepath, O_WRONLY | O_CREAT | O_EXCL)
>   If there is already a lockfile, this fails
>   Otherwise, it creates one.
>   This is atomic.
> - the logic of mythburn.py's try ... finally block at lines 3571
>   through 3611 seems wrong.  The finally part removes the lock file
>   but it may not belong to this process.  Luckilly, the program that
>   invokes mythburn.py will not do so if the lock is present.  So this
>   case will not come up.  Still, this seems quite wrong.
> - the lock file, when present, simply contains the string "lock".  It
>   is better to follow the convention that the lock file contains the
>   process ID of the owning process.  This allows people and processes
>   to determine if a lock is stale: held by a now-dead process.
> - It seems to me that each place where the lock is checked should then
>   check to see if the lock is stale and act accordingly (break the
>   lock if stale, perhaps with a warning).
> Once this last step is implemented, my problem 2 will go away.
> I started to code changes to mythburn.py but before getting serious,
> I'd like to know if the relevant authorities think I'm on the right
> track.

I can't say it's ever been a problem for me but if you want to code 
these changes then go ahead. You'll also need to look at 
mytharchivehelper which also sometimes creates the lock file.

Paul H.

More information about the mythtv-dev mailing list