Skip to content

Commit

Permalink
Fixes #12960 - Remote idle frontend wakes backend if WOL is set
Browse files Browse the repository at this point in the history
The frontend while idle will let the backend shut down. Also if
idle is exited on the frontend the backend will wake if WOL for
backend and database are set.

Also some small setup improvements.
  • Loading branch information
bennettpeter committed Jul 5, 2017
1 parent 6a85449 commit 119d733
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions mythtv/libs/libmyth/mythcontext.cpp
Expand Up @@ -1341,6 +1341,11 @@ void MythContextPrivate::ShowConnectionFailurePopup(bool persistent)
if (m_lastCheck.isValid() && now < m_lastCheck)
return;

// When WOL is disallowed, standy mode,
// we should not show connection failures.
if (!gCoreContext->IsWOLAllowed())
return;

m_lastCheck = now.addMSecs(5000); // don't refresh notification more than every 5s

QString description = (persistent) ?
Expand Down
16 changes: 15 additions & 1 deletion mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -82,6 +82,7 @@ class MythCoreContextPrivate : public QObject
QMutex m_WOLInProgressLock;
QWaitCondition m_WOLInProgressWaitCondition;
bool m_WOLInProgress;
bool m_IsWOLAllowed;

bool m_backend;
bool m_frontend;
Expand Down Expand Up @@ -128,6 +129,7 @@ MythCoreContextPrivate::MythCoreContextPrivate(MythCoreContext *lparent,
m_sockLock(QMutex::NonRecursive),
m_serverSock(NULL), m_eventSock(NULL),
m_WOLInProgress(false),
m_IsWOLAllowed(true),
m_backend(false),
m_frontend(false),
m_database(GetMythDB()),
Expand Down Expand Up @@ -416,7 +418,9 @@ MythSocket *MythCoreContext::ConnectCommandSocket(
d->WaitForWOL();
}

QString WOLcmd = GetSetting("WOLbackendCommand", "");
QString WOLcmd;
if (IsWOLAllowed())
WOLcmd = GetSetting("WOLbackendCommand", "");

if (maxConnTry < 1)
maxConnTry = max(GetNumSetting("BackendConnectRetry", 1), 1);
Expand Down Expand Up @@ -604,6 +608,16 @@ bool MythCoreContext::IsBlockingClient(void) const
return d->m_blockingClient;
}

void MythCoreContext::SetWOLAllowed(bool allow)
{
d->m_IsWOLAllowed = allow;
}

bool MythCoreContext::IsWOLAllowed() const
{
return d->m_IsWOLAllowed;
}

void MythCoreContext::SetAsBackend(bool backend)
{
d->m_backend = backend;
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythbase/mythcorecontext.h
Expand Up @@ -115,6 +115,9 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void AllowShutdown(void);
bool IsBlockingClient(void) const; ///< is this client blocking shutdown

void SetWOLAllowed(bool allow);
bool IsWOLAllowed() const;

bool SendReceiveStringList(QStringList &strlist, bool quickTimeout = false,
bool block = true);
void SendMessage(const QString &message);
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythbase/mythdbcon.cpp
Expand Up @@ -164,9 +164,13 @@ bool MSqlDatabase::OpenDatabase(bool skipdb)
m_dbparms.dbHostName == "127.0.0.1")
m_db.setHostName("localhost");

// Default read timeout is 10 mins - set a better value 30 seconds
m_db.setConnectOptions(QString("MYSQL_OPT_READ_TIMEOUT=30"));

connected = m_db.open();

if (!connected && m_dbparms.wolEnabled)
if (!connected && m_dbparms.wolEnabled
&& gCoreContext->IsWOLAllowed())
{
int trycount = 0;

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythsocket.cpp
Expand Up @@ -682,7 +682,7 @@ void MythSocket::ConnectToHostReal(QHostAddress _addr, quint16 port, bool *ret)
if (ok)
{
m_tcpSocket->connectToHost(addr, port, QAbstractSocket::ReadWrite);
ok = m_tcpSocket->waitForConnected();
ok = m_tcpSocket->waitForConnected(5000);
}

if (ok)
Expand Down
15 changes: 15 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -3013,6 +3013,17 @@ void MythMainWindow::EnterStandby(bool manual)
GetMythDB()->GetSetting("menutheme", "defaultmenu"));
state.insert("currentlocation", GetMythUI()->GetCurrentLocation());
MythUIStateTracker::SetState(state);

// Cache WOL settings in case DB goes down
QString masterserver = gCoreContext->GetSetting
("MasterServerName");
gCoreContext->GetSettingOnHost
("BackendServerAddr", masterserver);
gCoreContext->GetMasterServerPort();
gCoreContext->GetSetting("WOLbackendCommand", "");

// While in standby do not attempt to wake the backend
gCoreContext->SetWOLAllowed(false);
}

void MythMainWindow::ExitStandby(bool manual)
Expand All @@ -3031,6 +3042,10 @@ void MythMainWindow::ExitStandby(bool manual)
LOG(VB_GENERAL, LOG_NOTICE, "Leaving standby mode");

d->standby = false;

// We may attempt to wake the backend
gCoreContext->SetWOLAllowed(true);

gCoreContext->BlockShutdown();

QVariantMap state;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythfrontend/globalsettings.cpp
Expand Up @@ -1761,7 +1761,7 @@ static HostCheckBoxSetting *UseVirtualKeyboard()

static HostSpinBoxSetting *FrontendIdleTimeout()
{
HostSpinBoxSetting *gs = new HostSpinBoxSetting("FrontendIdleTimeout", 0, 360, 15);
HostSpinBoxSetting *gs = new HostSpinBoxSetting("FrontendIdleTimeout", 0, 360, 5);

gs->setLabel(MainGeneralSettings::tr("Idle time before entering standby "
"mode (minutes)"));
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtv-setup/backendsettings.cpp
Expand Up @@ -418,7 +418,7 @@ static GlobalTextEditSetting *WOLbackendCommand()
gc->setLabel(QObject::tr("Wake command"));
gc->setValue("");
gc->setHelpText(QObject::tr("The command used to wake up your master "
"backend server (e.g. sudo /etc/init.d/mythtv-backend restart)."));
"backend server (e.g. wakeonlan 00:00:00:00:00:00)."));
return gc;
};

Expand Down

0 comments on commit 119d733

Please sign in to comment.