Skip to content

Commit

Permalink
Fix the faulty exit code 139 issue in Ubuntu systems
Browse files Browse the repository at this point in the history
I think it might be an oddity in eglibc, but the status return from waitpid()
is buggered sometimes for signalled children.  Rather than showing up as signal
11 for a segfault, it shows up as an exit value of 139.  This is the most
common offender, but signal 6 (exit value 134) shows up sometimes as well.

The workaround limits the valid exit values of the child to being 0-127.  An
exit value above that is assumed to be a buggered up signal return and is
byteswapped.

As this is most prevalent with mythcommflag, the workaround is only active
for mythcommflag (for now).  If other MythSystem calls need this added, we
can add it later.
  • Loading branch information
Beirdo committed Feb 27, 2012
1 parent 723d798 commit b967448
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mythtv/libs/libmythbase/mythsystem.cpp
Expand Up @@ -300,6 +300,8 @@ void MythSystem::ProcessFlags(uint flags)
m_settings["AutoCleanup"] = true;
if( flags & kMSAnonLog )
m_settings["AnonLog"] = true;
if( flags & kMSLowExitVal )
m_settings["OnlyLowExitVal"] = true;
}

QByteArray MythSystem::Read(int size)
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythbase/mythsystem.h
Expand Up @@ -22,6 +22,7 @@ typedef enum MythSystemMask {
kMSAbortOnJump = 0x00001000, //< abort this process on a jumppoint
kMSSetPGID = 0x00002000, //< set the process group id
kMSAutoCleanup = 0x00004000, //< automatically delete if backgrounded
kMSLowExitVal = 0x00008000, //< allow exit values 0-127 only
} MythSystemFlag;

#ifdef __cplusplus
Expand Down Expand Up @@ -73,8 +74,9 @@ class MBASE_PUBLIC MythSystem : public QObject

void JumpAbort(void);

bool isBackground() { return GetSetting("RunInBackground"); };
bool doAutoCleanup() { return GetSetting("AutoCleanup"); };
bool isBackground() { return GetSetting("RunInBackground"); };
bool doAutoCleanup() { return GetSetting("AutoCleanup"); };
bool onlyLowExitVal() { return GetSetting("OnlyLowExitVal"); };
void HandlePreRun();
void HandlePostRun();

Expand Down
16 changes: 16 additions & 0 deletions mythtv/libs/libmythbase/system-unix.cpp
Expand Up @@ -315,6 +315,22 @@ void MythSystemManager::run(void)

msList.append(ms);

// Deal with (primarily) Ubuntu which seems to consistently be
// screwing up and reporting the signalled case as an exit. This
// workaround will limit the valid exit value to 0 - 127. As all
// of our return values match that (other than the occasional 255)
// this shouldn't cause any issues
if (ms->m_parent->onlyLowExitVal() && WIFEXITED(status) &&
WEXITSTATUS(status) != 255 && WEXITSTATUS(status) & 0x80)
{
// Just byte swap the status and it seems to be correctly done
uint16_t oldstatus = status;
status = ((status & 0x00FF) << 8) | ((status & 0xFF00) >> 8);
LOG(VB_SYSTEM, LOG_INFO,
QString("Odd return value: swapping from %1 to %2")
.arg(oldstatus) .arg(status));
}

// handle normal exit
if( WIFEXITED(status) )
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/jobqueue.cpp
Expand Up @@ -2296,7 +2296,7 @@ void JobQueue::DoFlagCommercialsThread(int jobID)
LOG(VB_JOBQUEUE, LOG_INFO, LOC + QString("Running command: '%1'")
.arg(command));

breaksFound = myth_system(command);
breaksFound = myth_system(command, kMSLowExitVal);
int priority = LOG_NOTICE;
QString comment;

Expand Down

0 comments on commit b967448

Please sign in to comment.