Ticket #9421: 0001-Changes-to-MythSystemUnix-to-fix-when-a-launched-pro.patch

File 0001-Changes-to-MythSystemUnix-to-fix-when-a-launched-pro.patch, 5.2 KB (added by beirdo, 9 years ago)

replaces 0001-0003 for okolsi, rebased onto current master

  • mythtv/libs/libmythbase/mythsystem.cpp

    From e6f6334658d646246dc608e082c1b321907b2e4f Mon Sep 17 00:00:00 2001
    From: Gavin Hurlbut <ghurlbut@mythtv.org>
    Date: Mon, 3 Jan 2011 16:30:49 -0800
    Subject: [PATCH] Changes to MythSystemUnix to fix when a launched program dies quickly
    
    This hopefully will fix #9421 (first report).
    
    Make background runs not block the foreground
    
    The problem with running in the background in from the menu XML is that it is
    blocking the drawing, inputdevs, etc, and then launching in the background.
    If in the background, there is no reason I can think of that we need to block
    the UI thread.  If the program launched in the background has focus, it should
    be receiving the keyboard input.  The only one think I'm wondering is if LIRC
    will act oddly.
    
    Move timeout setting to before fork
    
    Don't bother managing a child that failed
    
    If the child quickly failed (i.e. errored on start), there is an apparent
    race condition that makes it look like the child timed out, and if it was run
    in the background, it's deleted before the manager thread gets it, so we core
    dump when we try to remove it.
    ---
     mythtv/libs/libmythbase/mythsystem.cpp     |   17 +++++++++++++----
     mythtv/libs/libmythbase/system-unix.cpp    |   12 ++++++------
     mythtv/libs/libmythbase/system-windows.cpp |   11 +++++------
     3 files changed, 24 insertions(+), 16 deletions(-)
    
    diff --git a/mythtv/libs/libmythbase/mythsystem.cpp b/mythtv/libs/libmythbase/mythsystem.cpp
    index 63532fb..e7cbe1a 100644
    a b void MythSystem::Run(time_t timeout) 
    151151
    152152    d->Fork(timeout);
    153153
    154     m_semReady.acquire(1);
    155     emit started();
    156     d->Manage();
     154    if( GetStatus() == GENERIC_EXIT_RUNNING )
     155    {
     156        m_semReady.acquire(1);
     157        emit started();
     158        d->Manage();
     159    }
     160    else
     161    {
     162        emit error(GetStatus());
     163    }
    157164}
    158165
    159166// should there be a separate 'getstatus' call? or is using
    void MythSystem::ProcessFlags(uint flags) 
    230237        return;
    231238    }
    232239
     240    m_settings["IsInUI"] = gCoreContext->HasGUI() && gCoreContext->IsUIThread();
     241
    233242    if( flags & kMSRunBackground )
    234243        m_settings["RunInBackground"] = true;
    235244
    void MythSystem::ProcessFlags(uint flags) 
    243252        m_command = m_command.trimmed();
    244253        m_settings["RunInBackground"] = true;
    245254        m_settings["UseShell"]        = true;
     255        m_settings["IsInUI"]          = false;
    246256    }
    247257
    248     m_settings["IsInUI"] = gCoreContext->HasGUI() && gCoreContext->IsUIThread();
    249258    if( GetSetting("IsInUI") )
    250259    {
    251260        // Check for UI-only locks
  • mythtv/libs/libmythbase/system-unix.cpp

    diff --git a/mythtv/libs/libmythbase/system-unix.cpp b/mythtv/libs/libmythbase/system-unix.cpp
    index c6d4560..2c43a4c 100644
    a b void MythSystemUnix::Fork(time_t timeout) 
    626626    if (GetSetting("SetDirectory") && !dir.isEmpty())
    627627        directory = strdup(dir.toUtf8().constData());
    628628
     629    /* Do this before forking in case the child miserably fails */
     630    m_timeout = timeout;
     631    if( timeout )
     632        m_timeout += time(NULL);
     633
    629634    pid_t child = fork();
    630635
    631636    if (child < 0)
    void MythSystemUnix::Fork(time_t timeout) 
    642647        m_pid = child;
    643648        SetStatus( GENERIC_EXIT_RUNNING );
    644649
    645         m_timeout = timeout;
    646 
    647650        VERBOSE(VB_SYSTEM|VB_EXTRA,
    648651                    QString("Managed child (PID: %1) has started! "
    649652                            "%2%3 command=%4, timeout=%5")
    650653                        .arg(m_pid) .arg(GetSetting("UseShell") ? "*" : "")
    651654                        .arg(GetSetting("RunInBackground") ? "&" : "")
    652                         .arg(GetLogCmd()) .arg(m_timeout));
    653 
    654         if( timeout )
    655             m_timeout += time(NULL);
     655                        .arg(GetLogCmd()) .arg(timeout));
    656656
    657657        /* close unused pipe ends */
    658658        CLOSE(p_stdin[0]);
  • mythtv/libs/libmythbase/system-windows.cpp

    diff --git a/mythtv/libs/libmythbase/system-windows.cpp b/mythtv/libs/libmythbase/system-windows.cpp
    index e6a7c2d..a6fbc35 100644
    a b void MythSystemWindows::Fork(time_t timeout) 
    633633    PROCESS_INFORMATION pi;
    634634    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    635635
     636    m_timeout = timeout;
     637    if( timeout )
     638        m_timeout += time(NULL);
     639
    636640    bool success = CreateProcess(NULL,
    637641                    command,       // command line
    638642                    NULL,          // process security attributes
    void MythSystemWindows::Fork(time_t timeout) 
    655659        m_child = pi.hProcess;
    656660        SetStatus( GENERIC_EXIT_RUNNING );
    657661
    658         m_timeout = timeout;
    659 
    660662        VERBOSE(VB_SYSTEM|VB_EXTRA,
    661663                QString("Managed child (Handle: %1) has started! "
    662664                        "%2%3 command=%4, timeout=%5")
    663665                    .arg((long long)m_child)
    664666                    .arg(GetSetting("UseShell") ? "*" : "")
    665667                    .arg(GetSetting("RunInBackground") ? "&" : "")
    666                     .arg(GetLogCmd()) .arg(m_timeout));
    667 
    668         if( timeout )
    669             m_timeout += time(NULL);
     668                    .arg(GetLogCmd()) .arg(timeout));
    670669
    671670        /* close unused pipe ends */
    672671        CLOSE(p_stdin[0]);