From 9a6535fba1ccef84fd8ede246912e0d7a7bf3eef Mon Sep 17 00:00:00 2001
From: Gavin Hurlbut <gjhurlbu@gmail.com>
Date: Thu, 7 Oct 2010 01:17:27 -0700
Subject: [PATCH] Redo the verbose_lock in myth_system


diff --git a/mythtv/libs/libmythdb/mythsystem.cpp b/mythtv/libs/libmythdb/mythsystem.cpp
index 7a4bcdb..b6196dd 100644
--- a/mythtv/libs/libmythdb/mythsystem.cpp
+++ b/mythtv/libs/libmythdb/mythsystem.cpp
@@ -373,8 +373,16 @@ pid_t myth_system_fork(const QString &command, uint &result)
 {
     QString LOC_ERR = QString("myth_system('%1'): Error: ").arg(command);
     VERBOSE(VB_GENERAL, QString("Launching: %1") .arg(command));
+
+    // Due to the possibility of forking during a call to currentDateTime from within
+    // VERBOSE, and thereby breaking VERBOSE in the children, lock the verbose_mutex
+    // to prevent this from ever happening.
+    verbose_mutex.lock();
+
     pid_t child = fork();
 
+    verbose_mutex.unlock();
+
     if (child < 0)
     {
         /* Fork failed */
@@ -386,12 +394,6 @@ pid_t myth_system_fork(const QString &command, uint &result)
     else if (child == 0)
     {
         /* Child */
-        /* In case we forked WHILE it was locked */
-        bool unlocked = verbose_mutex.tryLock();
-        verbose_mutex.unlock();
-        if( !unlocked )
-            VERBOSE(VB_GENERAL, "Cleared parent's verbose lock");
-
         /* Close all open file descriptors except stdout/stderr */
         for (int i = sysconf(_SC_OPEN_MAX) - 1; i > 2; i--)
             close(i);
-- 
1.7.0.4

