'@uptime' macro for unixes is implemented using /proc filesystem. If uptime isn't supported then writes message to log
This commit is contained in:
parent
615846e57d
commit
08e75a4a4d
@ -684,7 +684,6 @@ void TokenXlat(int mode, std::string &input, GMsg* msg, GMsg* oldmsg, int __orig
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WIN32__
|
|
||||||
if (strnieql(it2str(input, dst), "@uptime", 7))
|
if (strnieql(it2str(input, dst), "@uptime", 7))
|
||||||
{
|
{
|
||||||
size_t days = 0;
|
size_t days = 0;
|
||||||
@ -700,8 +699,29 @@ void TokenXlat(int mode, std::string &input, GMsg* msg, GMsg* oldmsg, int __orig
|
|||||||
QueryPerformanceFrequency(&frequency);
|
QueryPerformanceFrequency(&frequency);
|
||||||
seconds = counter.QuadPart / frequency.QuadPart;
|
seconds = counter.QuadPart / frequency.QuadPart;
|
||||||
useconds = size_t(double(counter.QuadPart % frequency.QuadPart)*1000 / frequency.QuadPart);
|
useconds = size_t(double(counter.QuadPart % frequency.QuadPart)*1000 / frequency.QuadPart);
|
||||||
|
#elif defined(__unix__)
|
||||||
|
FILE *fd = fopen("/proc/uptime","r");
|
||||||
|
if( fd )
|
||||||
|
{
|
||||||
|
char s[20];
|
||||||
|
if( fgets(s, sizeof(s), fd) )
|
||||||
|
{
|
||||||
|
if( sizeof(size_t) == sizeof(long) )
|
||||||
|
sscanf(s, "%lu.%2lu", &seconds, &useconds);
|
||||||
|
/* to future 64-bit unixtime
|
||||||
|
else if( sizeof(size_t) == sizeof(long long) )
|
||||||
|
sscanf(s, "%Lu.%2Lu", &seconds, &useconds);
|
||||||
|
*/
|
||||||
|
else if( sizeof(size_t) == sizeof(unsigned) )
|
||||||
|
sscanf(s, "%u.%2u", &seconds, &useconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
LOG.printf("Macros \"@uptime\" is not suppoted on platform %s!", __gver_platform__);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if( seconds+useconds>0 )
|
||||||
|
{
|
||||||
days = seconds/(60*60*24); seconds %= 60*60*24;
|
days = seconds/(60*60*24); seconds %= 60*60*24;
|
||||||
hours = seconds/(60*60); seconds %= 60*60;
|
hours = seconds/(60*60); seconds %= 60*60;
|
||||||
minutes = seconds/60; seconds %= 60;
|
minutes = seconds/60; seconds %= 60;
|
||||||
@ -717,7 +737,12 @@ void TokenXlat(int mode, std::string &input, GMsg* msg, GMsg* oldmsg, int __orig
|
|||||||
|
|
||||||
tokenxchg(input, dst, "@uptime", uptime.c_str());
|
tokenxchg(input, dst, "@uptime", uptime.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
else
|
||||||
|
{
|
||||||
|
LOG.printf("Can't determine uptime value, set @uptime empty.");
|
||||||
|
tokenxchg(input, dst, "@uptime", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dst++;
|
dst++;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user