mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-10 23:01:45 +02:00
uptime for FreeBSD
This commit is contained in:
parent
fe09554b78
commit
4ba7c7c834
1 changed files with 17 additions and 0 deletions
|
@ -19,6 +19,8 @@
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include "common/strCompat.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
@ -239,6 +241,21 @@ static long uptime()
|
||||||
sysinfo(&info);
|
sysinfo(&info);
|
||||||
return info.uptime;
|
return info.uptime;
|
||||||
#else
|
#else
|
||||||
|
std::string uptime = execGetOutput("sysctl kern.boottime");
|
||||||
|
if ((uptime.find(" sec = ") != std::string::npos) && (uptime.find(",") != std::string::npos))
|
||||||
|
{
|
||||||
|
uptime = trim_copy(uptime.substr(uptime.find(" sec = ") + 7));
|
||||||
|
uptime.resize(uptime.find(","));
|
||||||
|
timeval now;
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return now.tv_sec - cpt::stoul(uptime);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue