Ticket #9016: 0001-Remove-VERBOSE-from-myth_system-child.patch

File 0001-Remove-VERBOSE-from-myth_system-child.patch, 3.2 KB (added by beirdo, 9 years ago)
  • mythtv/libs/libmythdb/mythsystem.cpp

    From 1af9fe2bc8dc8b6e24157da522f72bbd32359ba2 Mon Sep 17 00:00:00 2001
    From: Gavin Hurlbut <gjhurlbu@gmail.com>
    Date: Thu, 7 Oct 2010 01:17:27 -0700
    Subject: [PATCH] Remove VERBOSE from myth_system child
    
    
    diff --git a/mythtv/libs/libmythdb/mythsystem.cpp b/mythtv/libs/libmythdb/mythsystem.cpp
    index 7a4bcdb..28a5da1 100644
    a b pid_t myth_system_fork(const QString &command, uint &result) 
    373373{
    374374    QString LOC_ERR = QString("myth_system('%1'): Error: ").arg(command);
    375375    VERBOSE(VB_GENERAL, QString("Launching: %1") .arg(command));
     376
    376377    pid_t child = fork();
    377378
    378379    if (child < 0)
    379380    {
    380         /* Fork failed */
     381        /* Fork failed, still in parent */
    381382        VERBOSE(VB_GENERAL, (LOC_ERR + "fork() failed because %1")
    382383                .arg(strerror(errno)));
    383384        result = GENERIC_EXIT_NOT_OK;
    pid_t myth_system_fork(const QString &command, uint &result) 
    385386    }
    386387    else if (child == 0)
    387388    {
    388         /* Child */
    389         /* In case we forked WHILE it was locked */
    390         bool unlocked = verbose_mutex.tryLock();
    391         verbose_mutex.unlock();
    392         if( !unlocked )
    393             VERBOSE(VB_GENERAL, "Cleared parent's verbose lock");
     389        /* Child - NOTE: it is not safe to use VERBOSE between the fork and
     390         * execl calls in the child.  It causes occasional locking issues that
     391         * cause deadlocked child processes. */
    394392
    395393        /* Close all open file descriptors except stdout/stderr */
    396394        for (int i = sysconf(_SC_OPEN_MAX) - 1; i > 2; i--)
    pid_t myth_system_fork(const QString &command, uint &result) 
    403401            // Note: dup2() will close old stdin descriptor.
    404402            if (dup2(fd, 0) < 0)
    405403            {
    406                 VERBOSE(VB_GENERAL, LOC_ERR +
     404                // Can't use VERBOSE due to locking fun.
     405                        QString message = LOC_ERR +
    407406                        "Cannot redirect /dev/null to standard input,"
    408                         "\n\t\t\tfailed to duplicate file descriptor." + ENO);
     407                        "\n\t\t\tfailed to duplicate file descriptor." + ENO;
     408                cerr << message.constData();
    409409            }
    410410            close(fd);
    411411        }
    412412        else
    413413        {
    414             VERBOSE(VB_GENERAL, LOC_ERR + "Cannot redirect /dev/null "
    415                     "to standard input, failed to open." + ENO);
     414            // Can't use VERBOSE due to locking fun.
     415            QString message = LOC_ERR + "Cannot redirect /dev/null "
     416                    "to standard input, failed to open." + ENO;
     417            cerr << message.constData();
    416418        }
    417419
    418420        /* Run command */
    419421        execl("/bin/sh", "sh", "-c", command.toUtf8().constData(), (char *)0);
    420422        if (errno)
    421423        {
    422             VERBOSE(VB_GENERAL, (LOC_ERR + "execl() failed because %1")
    423                     .arg(strerror(errno)));
     424            // Can't use VERBOSE due to locking fun.
     425            QString message = LOC_ERR + QString("execl() failed because %1")
     426                    .arg(strerror(errno));
     427            cerr << message.constData();
    424428        }
    425429
    426430        /* Failed to exec */