Ticket #4381: mythtv-misc_status_info_popen.patch

File mythtv-misc_status_info_popen.patch, 4.5 KB (added by sphery <mtdean@…>, 13 years ago)
  • programs/mythbackend/httpstatus.cpp

     
    2222#include <qfile.h>
    2323#include <qregexp.h>
    2424#include <qbuffer.h>
    25 #include <qprocess.h>
    2625#include <qlocale.h>
    2726#include <math.h>
     27#include <stdio.h>
    2828#include <stdlib.h>
    2929#include <unistd.h>
    3030
     
    411411        QDomElement misc = pDoc->createElement("Miscellaneous");
    412412        root.appendChild(misc);
    413413
    414         QProcess miscellaneous_status_info_proc(info_script);
    415         miscellaneous_status_info_proc.setCommunication(
    416                                           QProcess::Stdout|QProcess::Stderr);
     414        FILE *fp = popen(info_script.ascii(), "r");
    417415
    418         if (miscellaneous_status_info_proc.start())
     416        if (fp)
    419417        {
    420             int i = 0;
    421             // Since the miscellaneous status information is not critical
    422             // but creating the status document must wait for it, timeout
    423             // if the script takes more than 10 seconds to execute.
    424             while (miscellaneous_status_info_proc.isRunning() && i < 100)
     418            char buffer[256];
     419            int status;
     420            QString input = "";
     421
     422            while (fgets(buffer, sizeof(buffer), fp))
    425423            {
    426                 usleep(100000);
    427                 ++i;
     424                input.append(buffer);
    428425            }
    429426
    430             if (miscellaneous_status_info_proc.normalExit())
     427            if (pclose(fp))
    431428            {
    432                 QString input = "";
    433                 while (miscellaneous_status_info_proc.canReadLineStdout())
    434                 {
    435                     input = miscellaneous_status_info_proc.readLineStdout();
    436                     if (input.isEmpty())
    437                         continue;
     429                VERBOSE(VB_IMPORTANT, QString("Error running miscellaneous "
     430                        "status information script: %1").arg(info_script));
     431            }
     432            else
     433            {
     434                QStringList output = QStringList::split("\n", input, false);
    438435
     436                QStringList::iterator iter = output.begin();
     437                for (; iter != output.end(); iter++)
     438                {
    439439                    QDomElement info = pDoc->createElement("Information");
    440440
    441                     QStringList list = QStringList::split("[]:[]", input, true);
     441                    QStringList list = QStringList::split("[]:[]", *iter, true);
    442442                    unsigned int size = list.size();
    443443                    unsigned int hasAttributes = 0;
    444444
     
    463463                        misc.appendChild(info);
    464464                }
    465465            }
    466             else
    467             {
    468                 VERBOSE(VB_IMPORTANT, QString("Error running miscellaneous "
    469                         "status information script or execution timed out: %1")
    470                         .arg(info_script));
    471             }
    472466        }
    473467        else
    474468        {
  • contrib/misc_status_info/README

     
    4242If four (or more) fields are output on a line, the extra fields will be
    4343ignored.
    4444
    45 The script must provide output within 10 seconds or the Miscellaneous status
    46 information will not be included on the status page.  This timeout forces the
    47 status page to be returned in a reasonably short period of time regardless of
    48 the script specified.  If you would like to provide information that requires
    49 more than 10 seconds to compute (or that comes from a remote system whose
    50 response time is unknown), you may want to set up another script, i.e. in a
    51 cron job, and poll the data at appropriate intervals and write the output to a
    52 file, which could then be read (or simply cat'ed, if in the proper format) by
    53 the miscellaneous status script.
     45The script should provide output quickly to ensure the status page is returned
     46in a reasonably short period of time.  If you would like to provide information
     47that requires a significant amount of time to compute (or that comes from a
     48remote system whose response time is unknown), you may want to set up another
     49script, i.e. in a cron job, and poll the data at appropriate intervals and
     50write the output to a file, which could then be read (or simply cat'ed, if in
     51the proper format) by the miscellaneous status script.
    5452
    5553Thermal Information
    5654-------------------