20 changes: 10 additions & 10 deletions mythtv/libs/libmythbase/mythsystemunix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void MythSystemLegacyManager::run(void)
// loop through running processes for any that require action
MSMap_t::iterator i;
MSMap_t::iterator next;
time_t now = time(nullptr);
auto now = SystemClock::now();

m_mapLock.lock();
m_jumpLock.lock();
Expand All @@ -387,7 +387,7 @@ void MythSystemLegacyManager::run(void)
continue;

// handle processes beyond marked timeout
if( ms->m_timeout > 0 && ms->m_timeout < now )
if( ms->m_timeout.time_since_epoch() > 0s && ms->m_timeout < now )
{
// issuing KILL signal after TERM failed in a timely manner
if( ms->GetStatus() == GENERIC_EXIT_TIMEOUT )
Expand All @@ -396,7 +396,7 @@ void MythSystemLegacyManager::run(void)
QString("Managed child (PID: %1) timed out"
", issuing KILL signal").arg(pid));
// Prevent constant attempts to kill an obstinate child
ms->m_timeout = 0;
ms->m_timeout = SystemTime(0s);
ms->Signal(SIGKILL);
}

Expand All @@ -407,7 +407,7 @@ void MythSystemLegacyManager::run(void)
QString("Managed child (PID: %1) timed out"
", issuing TERM signal").arg(pid));
ms->SetStatus( GENERIC_EXIT_TIMEOUT );
ms->m_timeout = now + 1;
ms->m_timeout = now + 1s;
ms->Term();
}
}
Expand Down Expand Up @@ -750,7 +750,7 @@ void MythSystemLegacyUnix::Term(bool force)
if( force )
{
// send KILL if it does not exit within one second
if( m_parent->Wait(1) == GENERIC_EXIT_RUNNING )
if( m_parent->Wait(1s) == GENERIC_EXIT_RUNNING )
Signal(SIGKILL);
}
}
Expand All @@ -772,7 +772,7 @@ void MythSystemLegacyUnix::Signal( int sig )
}

#define MAX_BUFLEN 1024
void MythSystemLegacyUnix::Fork(time_t timeout)
void MythSystemLegacyUnix::Fork(std::chrono::seconds timeout)
{
QString LOC_ERR = QString("myth_system('%1'): Error: ").arg(GetLogCmd());

Expand Down Expand Up @@ -916,9 +916,9 @@ void MythSystemLegacyUnix::Fork(time_t timeout)
int ioprioval = m_parent->GetIOPrio();

/* Do this before forking in case the child miserably fails */
m_timeout = timeout;
if( timeout )
m_timeout += time(nullptr);
m_timeout = ( timeout != 0s )
? SystemClock::now() + timeout
: SystemClock::time_point();

listLock.lock();
pid_t child = fork();
Expand All @@ -941,7 +941,7 @@ void MythSystemLegacyUnix::Fork(time_t timeout)
"%2%3 command=%4, timeout=%5")
.arg(m_pid) .arg(GetSetting("UseShell") ? "*" : "")
.arg(GetSetting("RunInBackground") ? "&" : "")
.arg(GetLogCmd()) .arg(timeout));
.arg(GetLogCmd()).arg(timeout.count()));

/* close unused pipe ends */
if (p_stdin[0] >= 0)
Expand Down
5 changes: 3 additions & 2 deletions mythtv/libs/libmythbase/mythsystemunix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "mythsystemprivate.h"
#include "mythbaseexp.h"
#include "mythchrono.h"
#include "mythsystemlegacy.h"
#include "mthread.h"

Expand Down Expand Up @@ -96,7 +97,7 @@ class MBASE_PUBLIC MythSystemLegacyUnix : public MythSystemLegacyPrivate
explicit MythSystemLegacyUnix(MythSystemLegacy *parent);
~MythSystemLegacyUnix() override = default;

void Fork(time_t timeout) override; // MythSystemLegacyPrivate
void Fork(std::chrono::seconds timeout) override; // MythSystemLegacyPrivate
void Manage(void) override; // MythSystemLegacyPrivate

void Term(bool force=false) override; // MythSystemLegacyPrivate
Expand All @@ -112,7 +113,7 @@ class MBASE_PUBLIC MythSystemLegacyUnix : public MythSystemLegacyPrivate

private:
pid_t m_pid {0};
time_t m_timeout {0};
SystemTime m_timeout {0s};

std::array<int,3> m_stdpipe {-1, -1, -1};
};
Expand Down
18 changes: 9 additions & 9 deletions mythtv/libs/libmythbase/mythsystemwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void MythSystemLegacyManager::run(void)

// loop through running processes for any that require action
MSMap_t::iterator i;
time_t now = time(nullptr);
auto now = SystemClock::now();

m_mapLock.lock();
m_jumpLock.lock();
Expand All @@ -320,7 +320,7 @@ void MythSystemLegacyManager::run(void)
ms = i.value();

// handle processes beyond marked timeout
if( ms->m_timeout > 0 && ms->m_timeout < now )
if( ms->m_timeout.time_since_epoch() > 0s && ms->m_timeout < now )
{
// issuing KILL signal after TERM failed in a timely manner
if( ms->GetStatus() == GENERIC_EXIT_TIMEOUT )
Expand All @@ -329,7 +329,7 @@ void MythSystemLegacyManager::run(void)
QString("Managed child (Handle: %1) timed out, "
"issuing KILL signal").arg((long long)child));
// Prevent constant attempts to kill an obstinate child
ms->m_timeout = 0;
ms->m_timeout = SystemTime(0s);
ms->Signal(SIGKILL);
}

Expand All @@ -340,7 +340,7 @@ void MythSystemLegacyManager::run(void)
QString("Managed child (Handle: %1) timed out"
", issuing TERM signal").arg((long long)child));
ms->SetStatus( GENERIC_EXIT_TIMEOUT );
ms->m_timeout = now + 1;
ms->m_timeout = now + 1s;
ms->Term();
}
}
Expand Down Expand Up @@ -585,7 +585,7 @@ void MythSystemLegacyWindows::Signal( int sig )


#define MAX_BUFLEN 1024
void MythSystemLegacyWindows::Fork(time_t timeout)
void MythSystemLegacyWindows::Fork(std::chrono::seconds timeout)
{
BOOL bInherit = FALSE;

Expand Down Expand Up @@ -699,9 +699,9 @@ void MythSystemLegacyWindows::Fork(time_t timeout)
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));

m_timeout = timeout;
if( timeout )
m_timeout += time(nullptr);
m_timeout = (timeout != 0s)
? SystemClock::now() + timeout
: SystemClock::time_point();

LPCWSTR pDir = nullptr;
if (dir.length() > 0)
Expand Down Expand Up @@ -739,7 +739,7 @@ void MythSystemLegacyWindows::Fork(time_t timeout)
.arg((long long)m_child)
.arg(GetSetting("UseShell") ? "*" : "")
.arg(GetSetting("RunInBackground") ? "&" : "")
.arg(GetLogCmd()) .arg(timeout));
.arg(GetLogCmd()).arg(timeout.count()));

/* close unused pipe ends */
CLOSE(p_stdin[0]);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythbase/mythsystemwindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MBASE_PUBLIC MythSystemLegacyWindows : public MythSystemLegacyPrivate
explicit MythSystemLegacyWindows(MythSystemLegacy *parent);
~MythSystemLegacyWindows() = default;

void Fork(time_t timeout) override; // MythSystemLegacyPrivate
void Fork(std::chrono::seconds timeout) override; // MythSystemLegacyPrivate
void Manage(void) override; // MythSystemLegacyPrivate

void Term(bool force=false) override; // MythSystemLegacyPrivate
Expand All @@ -108,7 +108,7 @@ class MBASE_PUBLIC MythSystemLegacyWindows : public MythSystemLegacyPrivate

private:
HANDLE m_child {nullptr};
time_t m_timeout {0};
SystemTime m_timeout {0s};

HANDLE m_stdpipe[3];
};
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythmetadata/imagemetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ QStringList VideoMetaData::GetAllTags()

MythSystemLegacy ffprobe(cmd, args, kMSRunShell | kMSStdOut);

ffprobe.Run(5);
ffprobe.Run(5s);

if (ffprobe.Wait() != GENERIC_EXIT_OK)
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythmetadata/imagethumbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ QString ThumbThread<DBFS>::CreateThumbnail(ImagePtrK im, int thumbPriority)
kMSPropagateLogs);
ms.SetNice(10);
ms.SetIOPrio(7);
ms.Run(30);
ms.Run(30s);
if (ms.Wait() != GENERIC_EXIT_OK)
{
LOG(VB_GENERAL, LOG_ERR, QString("Failed to run %2 %3")
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythmetadata/metadatagrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "mythcorecontext.h"

#define LOC QString("Metadata Grabber: ")
#define kGrabberRefresh 60
static constexpr std::chrono::seconds kGrabberRefresh { 60s };

static GrabberList s_grabberList;
static QMutex s_grabberLock;
Expand Down Expand Up @@ -80,7 +80,7 @@ GrabberList MetaGrabberScript::GetList(GrabberType type,
// this might have to be revised, or made more intelligent if
// the delay during refreshes is too great
if (refresh || !s_grabberAge.isValid() ||
(s_grabberAge.secsTo(now) > kGrabberRefresh))
(s_grabberAge.secsTo(now) > kGrabberRefresh.count()))
{
s_grabberList.clear();
LOG(VB_GENERAL, LOG_DEBUG, LOC + "Clearing grabber cache");
Expand Down Expand Up @@ -171,7 +171,7 @@ MetaGrabberScript MetaGrabberScript::GetType(const GrabberType type)
cmd = grabberTypes[type].m_def;
}

if (s_grabberAge.isValid() && s_grabberAge.secsTo(MythDate::current()) <= kGrabberRefresh)
if (s_grabberAge.isValid() && MythDate::secsInPast(s_grabberAge) <= kGrabberRefresh)
{
// just pull it from the cache
GrabberList list = GetList();
Expand Down Expand Up @@ -388,7 +388,7 @@ MetadataLookupList MetaGrabberScript::RunGrabber(const QStringList &args,
.arg(m_fullcommand).arg(args.join(" ")));

grabber.Run();
if (grabber.Wait(180) != GENERIC_EXIT_OK)
if (grabber.Wait(180s) != GENERIC_EXIT_OK)
return list;

QByteArray result = grabber.ReadAll();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/previewgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool PreviewGenerator::Run(void)
ms->SetNice(10);
ms->SetIOPrio(7);

ms->Run(30);
ms->Run(30s);
uint ret = ms->Wait();
delete ms;

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class XMLTVGrabber : public MythUIComboBoxSetting

MythSystemLegacy find_grabber_proc("tv_find_grabbers", args,
kMSStdOut | kMSRunShell);
find_grabber_proc.Run(25);
find_grabber_proc.Run(25s);
LOG(VB_GENERAL, LOG_INFO,
loc + "Running 'tv_find_grabbers " + args.join(" ") + "'.");
uint status = find_grabber_proc.Wait();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythbackend/httpstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ void HttpStatus::FillStatusXML( QDomDocument *pDoc )

uint flags = kMSRunShell | kMSStdOut;
MythSystemLegacy ms(info_script, flags);
ms.Run(10);
ms.Run(10s);
if (ms.Wait() != GENERIC_EXIT_OK)
{
LOG(VB_GENERAL, LOG_ERR,
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythfilldatabase/filldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ bool FillData::Run(SourceList &sourcelist)
MythSystemLegacy grabber_capabilities_proc(xmltv_grabber,
QStringList("--capabilities"),
flags);
grabber_capabilities_proc.Run(25);
grabber_capabilities_proc.Run(25s);
if (grabber_capabilities_proc.Wait() != GENERIC_EXIT_OK)
{
LOG(VB_GENERAL, LOG_ERR,
Expand Down Expand Up @@ -400,7 +400,7 @@ bool FillData::Run(SourceList &sourcelist)
MythSystemLegacy grabber_method_proc(xmltv_grabber,
QStringList("--preferredmethod"),
flags);
grabber_method_proc.Run(15);
grabber_method_proc.Run(15s);
if (grabber_method_proc.Wait() != GENERIC_EXIT_OK)
{
LOG(VB_GENERAL, LOG_ERR,
Expand Down