[mythtv] mythtv-backend: stopping/restarting while transcoding in progress loses recording

Matt Zimmerman mdz at debian.org
Wed Jun 2 16:06:12 EDT 2004


Forwarding this on to the list...

The way to fix this right is probably to have a locking mechanism of some
sort, so that the .tmp files are not cleared out if they are in use.

However, in the near term, I think the attached patch should avoid losing
the file.  Please test it if you can.

----- Forwarded message from Ove Kaaven <ovek at arcticnet.no> -----

Date: Wed, 02 Jun 2004 12:43:53 +0200
From: Ove Kaaven <ovek at arcticnet.no>
To: mdz at debian.org
Subject: mythtv-backend: stopping/restarting while transcoding in progress loses
 recording

Package: mythtv-backend
Version: 0.15.1-1
Severity: normal

If you configure mythtv to autotranscode shows, you apparently have to be
careful to make sure no transcodes are in progress when stopping and
restarting mythtv-backend (e.g. when running apt-get upgrade), or the
show being transcoded will be lost. What apparently happens is that
mythtranscode reads from the *.nuv file and writes to *.nuv.tmp,
then renames the *.nuv.tmp file to *.nuv to replace the old *.nuv
file when it's done. But when mythtv-backend is starting up, it deletes
any *.nuv.tmp files it can find, even if a mythtranscode is still running.
After this, when mythtranscode completes, it deletes the old *.nuv file
and tries to rename the *.nuv.tmp, which has been unlinked long ago, with
the result that both copies are lost, with no way to recover the recording.

There are probably several ways to fix this. For example,
/etc/init.d/mythtv-backend stop could kill off any mythtranscode
processes to avoid the issue. Or mythtranscode could check that the
*.nuv.tmp file still exists before deleting the *.nuv file. (Perhaps
the latter would be best since the backend could crash for other reasons
than a clean shutdown from the init script...)

In any case, some solution to this issue would be good.

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.26-1-k7
Locale: LANG=no_NO, LC_CTYPE=no_NO

Versions of packages mythtv-backend depends on:
ii  cron                      3.0pl1-83      management of regular background p
ii  debconf                   1.4.25         Debian configuration management sy
ii  libartsc0                 1.2.2-2        aRts Sound system C support librar
ii  libc6                     2.3.2.ds1-13   GNU C Library: Shared libraries an
ii  libfreetype6              2.1.7-2        FreeType 2 font engine, shared lib
ii  libgcc1                   1:3.3.3-9      GCC support library
ii  liblame0                  3.96-1         LAME Ain't an MP3 Encoder
ii  libmyth-0.15              0.15.1-1       Common library code for MythTV and
ii  libqt3c102-mt             3:3.2.3-2      Qt GUI Library (Threaded runtime v
ii  libstdc++5                1:3.3.3-9      The GNU Standard C++ Library v3
ii  libx11-6                  4.3.0.dfsg.1-4 X Window System protocol client li
ii  libxext6                  4.3.0.dfsg.1-4 X Window System miscellaneous exte
ii  libxv1                    4.3.0.dfsg.1-4 X Window System video extension li
ii  mythtv-common             0.15.1-1       A personal video recorder applicat
ii  wget                      1.9.1-4        retrieves files from the web
ii  xlibs                     4.3.0.dfsg.1-4 X Window System client libraries m

-- debconf information:
* mythtv/create_v4l_devs: true
* mythtv/run_setup: 

----- End forwarded message -----

-- 
 - mdz
-------------- next part --------------
Index: programs/mythbackend/transcoder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/transcoder.cpp,v
retrieving revision 1.16
diff -u -r1.16 transcoder.cpp
--- programs/mythbackend/transcoder.cpp	2 Jun 2004 03:45:29 -0000	1.16
+++ programs/mythbackend/transcoder.cpp	2 Jun 2004 20:05:52 -0000
@@ -279,10 +279,20 @@
                     // To save the original file...
                     QString oldfile = filename;
                     oldfile += ".old";
-                    rename (filename, oldfile);
-                    rename (tmpfile, filename);
-                    if (!gContext->GetNumSetting("SaveTranscoding", 0))
-                        unlink(oldfile);
+
+                    if (gContext->GetNumSetting("SaveTranscoding", 0))
+                        if (rename(filename, oldfile) != 0)
+                        {
+                            perror(QString("rename(%1,%2)").arg(filename).arg(oldfile).ascii());
+                            continue;
+                        }
+
+                    if (rename(tmpfile, filename) != 0)
+                    {
+                        perror(QString("rename(%1,%2)").arg(tmpfile).arg(filename).ascii());
+                        continue;
+                    }
+
                     DeleteTranscode(pinfo);
                     if (flags & TRANSCODE_USE_CUTLIST)
                     {


More information about the mythtv-dev mailing list