Ticket #4381: mythtv-misc_status_info_popen-20080124.patch
File mythtv-misc_status_info_popen-20080124.patch, 4.5 KB (added by , 16 years ago) |
---|
-
programs/mythbackend/httpstatus.cpp
22 22 #include <qfile.h> 23 23 #include <qregexp.h> 24 24 #include <qbuffer.h> 25 #include <qprocess.h>26 25 #include <qlocale.h> 27 26 #include <math.h> 27 #include <stdio.h> 28 28 #include <stdlib.h> 29 29 #include <unistd.h> 30 30 … … 411 411 QDomElement misc = pDoc->createElement("Miscellaneous"); 412 412 root.appendChild(misc); 413 413 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"); 417 415 418 if ( miscellaneous_status_info_proc.start())416 if (fp) 419 417 { 420 int i = 0;421 // Since the miscellaneous status information is not critical422 // but creating the status document must wait for it, timeout423 // 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)) 425 423 { 426 usleep(100000); 427 ++i; 424 input.append(QString::fromUtf8(buffer)); 428 425 } 429 426 430 if ( miscellaneous_status_info_proc.normalExit())427 if (pclose(fp)) 431 428 { 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); 438 435 436 QStringList::iterator iter = output.begin(); 437 for (; iter != output.end(); iter++) 438 { 439 439 QDomElement info = pDoc->createElement("Information"); 440 440 441 QStringList list = QStringList::split("[]:[]", input, true);441 QStringList list = QStringList::split("[]:[]", *iter, true); 442 442 unsigned int size = list.size(); 443 443 unsigned int hasAttributes = 0; 444 444 … … 463 463 misc.appendChild(info); 464 464 } 465 465 } 466 else467 {468 VERBOSE(VB_IMPORTANT, QString("Error running miscellaneous "469 "status information script or execution timed out: %1")470 .arg(info_script));471 }472 466 } 473 467 else 474 468 { -
contrib/misc_status_info/README
42 42 If four (or more) fields are output on a line, the extra fields will be 43 43 ignored. 44 44 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. 45 The script should provide output quickly to ensure the status page is returned 46 in a reasonably short period of time. If you would like to provide information 47 that requires a significant amount of time to compute (or that comes from a 48 remote system whose response time is unknown), you may want to set up another 49 script, i.e. in a cron job, and poll the data at appropriate intervals and 50 write the output to a file, which could then be read (or simply cat'ed, if in 51 the proper format) by the miscellaneous status script. 54 52 55 53 Thermal Information 56 54 -------------------