QT UTC linux Clock skew detected. Your build may be incomplete - c++

I have a code which I am writing it in QT (C++) where I want to display a date on a dateTime display on the GUI.. I get the time from another component and then I parse it into argument list and then I use Qprocess to run date - u command .. anyhow it seems like my make doesn't like what I am doing because it prints out this error:
QT UTC linux Clock skew detected. Your build may be incomplete.
the whole purpose of what I am doing is to update the UTC time of my linux computer according to the value I am getting and then gets that date using QT code to get the computer UTC time
here is part of the code :
if(month<10)
{
argument = "0"+ argument + QString::number(month);
}
else
{
argument = argument + QString::number(month);
}
if(day<10)
{
argument = "0"+ argument + QString::number(day);
}
else
{
argument = argument + QString::number(day);
}
if(hourUTC<10)
{
argument = "0" + argument + QString::number(hourUTC);
}
else
{
argument = argument + QString::number(hourUTC);
}
if(minUTC<10)
{
argument = "0"+ argument + QString::number(minUTC);
}
else
{
argument = argument + QString::number(minUTC);
}
argument = argument + QString::number(year);
argument = argument + ".";
if(secUTC<10)
{
argument = "0"+ argument + QString::number(secUTC);
}
else
{
argument = argument + QString::number(secUTC);
}
//argument = argument + QString::number((qint32)qRound(msUTC/ 1000.0));
argumentlist << argument;
qDebug() << argumentlist;
QProcess* proc = new QProcess();
// Change system date and time "date -u MMDDhhmmYYYY.ss" in tha application the date is created dynamically
proc->start(program, argumentlist);
proc->waitForFinished();
m_pOi->setTime();
any idea how can I force the change in time to my compute ? and yea I do run the code as a super user !

I think this error happens when your file times are newer than your system clock. make warns you that it may not be building everything correctly because of this. touching all your files should sort out the problem.
One of the causes is an SCM system that preserves file times and is ahead of your system clock.

Related

Passing a variable in System() c++

if (t.elapsed_millisecs() > 500) {
system(("powershell(Get - WmiObject - Namespace root / WMI - Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, " + brightness + string(")")).c_str());
t = {};
}
brightness is just an int that can be set from 1 to 100
I'm trying to change the brightness over a certain amount of time but I'm having problem with system() function. When the program tries to execute the system() function, the cmd outputs " '_' is not recognized as an internal or external command, operable program or batch file."
My question is how do you pass a variable to the system function correctly?
You are taking liberty with spaces in your example.
This one runs OK:
int brightness = 42;
string s = "powershell(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, ";
s += to_string(brightness);
s += ")";
cout << s;
system(s.c_str());
It doesn't change the brightness though, but I don't know WMI...
I can run this in PowerShell console:
$myMonitor = Get-WmiObject -Namespace root\wmi -Class WmiMonitorBrightnessMethods
$myMonitor.wmisetbrightness(3,50)
Same result - no errors, no effect.
UPDATE:
It works! (I was testing over Remote Desktop at first)

How to convert the output of boost::interprocess::winapi::get_last_bootup_time() to the unix time?

I need to get the time of the latest system boot. I'm using the following boost function:
#include <boost/interprocess/detail/win32_api.hpp>
std::string SystemLastBootTime = "";
if (boost::interprocess::winapi::get_last_bootup_time(SystemLastBootTime)) {
MessageBox(NULL, SystemLastBootTime.c_str(), "Last Boot Time", MB_OK | MB_ICONEXCLAMATION);
}
The output of SystemLastBootTime is:
AA000000_0E030000
What's exactly in this string, and how to convert it to a "normal" unix time, so I can compare and see if the system booted during the last 5 minutes or later?
The implementation is right there. There's actually different implementations:
when BOOST_INTERPROCESS_BOOTSTAMP_IS_SESSION_MANAGER_BASED is defined
when BOOST_INTERPROCESS_BOOTSTAMP_IS_EVENTLOG_BASED is defined
From Session Manager
inline bool get_last_bootup_time(std::string &stamp)
{
unsigned dword_val = 0;
std::size_t dword_size = sizeof(dword_val);
bool b_ret = get_registry_value_buffer( hkey_local_machine
, "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management\\PrefetchParameters"
, "BootId", &dword_val, dword_size);
if (b_ret)
{
char dword_str[sizeof(dword_val)*2u+1];
buffer_to_narrow_str(&dword_val, dword_size, dword_str);
dword_str[sizeof(dword_val)*2] = '\0';
stamp = dword_str;
b_ret = get_registry_value_buffer( hkey_local_machine
, "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power"
, "HybridBootAnimationTime", &dword_val, dword_size);
//Old Windows versions have no HybridBootAnimationTime
if(b_ret)
{
buffer_to_narrow_str(&dword_val, dword_size, dword_str);
dword_str[sizeof(dword_val)*2] = '\0';
stamp += "_";
stamp += dword_str;
}
b_ret = true;
}
return b_ret;
}
From Event Log
This is even grittier, and way more code since apparently they chose not to use an existing library. They end up looking for event ID 6005, and then reading the
unsigned long TimeGenerated; // Seconds since 1-1-1970
from that record.
Summarizing
As you can see the whole thing is proprietary, and you might just want to implement it yourself without (ab)using implementation details from Boost Interprocess.
The "good news" is that you might be able to get some documentation from Microsoft about either the Session Manager registry key, or System event 6005.
Oh, and don't forget that defining BOOST_INTERPROCESS_BOOTSTAMP_IS_EVENTLOG_BASED could we result in a readable timestamp to begin with, since it just formats the UNIX timestamp with %u to the output.

how to change os.system() call to subprocess.call() for below code

Need to know how i can convert below code from os.system to subprocess.call with shell=False
Code to be modified:
command1="ls -lrt"
command2="cat file.txt"
cucDBServiceStartRC = os.WEXITSTATUS(os.system(command1 + " && " + command2))
if(cucDBServiceStartRC!=0);
do something..
I Tried:
command1="ls -lrt"
command2="cat file.txt"
cucDBServiceStartRC = os.WEXITSTATUS(subprocess.call(shlex.split(command1 + " && " + command2),shell=False))
if(cucDBServiceStartRC!=0);
do something..
But command fails to compile.
Note: I want to do it with shell=False, so i need workaround for && ( used in above code for os.system) to be used in subprocess to run 2 commands at a time.
&& is a shell operator. If you want to run two programs without a shell inbetween, you need to run subprocess.call twice:
returnCode = subprocess.call(shlex.split(command1), shell=False);
if returnCode == 0:
returnCode = subprocess.call(shlex.split(command2), shell=False);
// Do whatever with returnCode. A value of 0 means either command failed.
It would be better, not to split the command line with shlex.split. Instead keep the executable name separate from the arguments from the beginning. Otherwise, if the user can influence the content of command1 or command2, you will have the same security concerns as with shell=True.

ColdFusion - Get next scheduled task due to run

This thread was useful in finding out the next run-time for a scheduled task.
How do I find out the next run time for a Scheduled Task?
But, is there also a way to simply get the next scheduled task due to run?
If I can get the date and name of the next task due to run, I can plug that date into a jQuery countdown timer, which will display a countdown to the next scheduled task, something like:
TaskABC due to run in:
12 03 20
hrs min sec
. This is for an admin interface in case you're wondering how geeky can people get:-)
EDIT
I had the same thought as Bill. But was curious if there was another way.
I poked around and apparently the internal Scheduler class maintains a list of upcoming tasks. The list is private, but you can use the same reflection technique to access it. Interestingly the list also includes system tasks like the mail spooler, session/application trackers, watchers, etecetera. So you must iterate through it until you find a "scheduled task" ie CronTabEntry
Below is a very lightly tested function that seems to do the trick in CF9. (Note, includes the CreateTimeStruct function from http://www.cflib.org).
Rules:
Returns a structure containing the name and time remaining until the next task. If no tasks were found, result.task is an empty string.
Excludes paused tasks
Usage:
result = new TaskUtil().getNextTask();
WriteDump(result);
CFC
component {
public struct function getNextTask() {
// get list of upcoming tasks from factory (UNDOCUMENTED)
local.scheduler = createObject("java", "coldfusion.server.ServiceFactory").getSchedulerService();
local.taskField = local.scheduler.getClass().getDeclaredField("_tasks");
local.taskField.setAccessible( true );
local.taskList = local.taskField.get(local.scheduler);
// taskList contains system jobs too, so we must iterate
// through the tasks to find the next "scheduled task"
local.nextTask = "";
local.tasks = local.taskList.iterator();
while ( local.tasks.hasNext() ) {
local.currTask = local.tasks.next();
local.className = local.currTask.getRunnable().getClass().name;
// exit as soon as we find a scheduled task that is NOT paused
if (local.className eq "coldfusion.scheduling.CronTabEntry"
&& !local.currTask.getRunnable().paused) {
local.nextTask = local.currTask;
break;
}
}
// if we found a task, calculate how many days, hours, etcetera
// until its next run time
local.details = { task="", remaining={} };
if ( isObject(local.nextTask) ) {
local.secondsToGo = (local.nextTask.getWhen() - now().getTime()) / 1000;
local.details.task = local.nextTask.getRunnable().task;
local.details.remaining = createTimeStruct(local.secondsToGo);
local.details.nextDate = dateAdd("s", local.nextTask.getWhen() / 1000
, "January 1 1970 00:00:00" );
}
return local.details;
}
/**
* Abbreviated version of CreateTimeStruct by Dave Pomerance
* See http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=421
*
* #param timespan The timespan to convert.
* #return Returns a structure.
* #author Dave Pomerance
* #version 1, January 7, 2002
*/
public struct function CreateTimeStruct(required numeric timespan) {
var timestruct = StructNew();
var mask = "s";
// only 4 allowed values for mask - if not one of those, return blank struct
if (ListFind("d,h,m,s", mask)) {
// compute seconds
if (mask eq "s") {
timestruct.s = (timespan mod 60) + (timespan - Int(timespan));
timespan = int(timespan/60);
mask = "m";
} else timestruct.s = 0;
// compute minutes
if (mask eq "m") {
timestruct.m = timespan mod 60;
timespan = int(timespan/60);
mask = "h";
} else timestruct.m = 0;
// compute hours, days
if (mask eq "h") {
timestruct.h = timespan mod 24;
timestruct.d = int(timespan/24);
} else {
timestruct.h = 0;
timestruct.d = timespan;
}
}
return timestruct;
}
}
My first thought is to iterate Leigh's getNextRunTime(string taskName) function over the collection of tasks. You can get an array of structs containing the details of all scheduled tasks using taskArray = createobject("java","coldfusion.server.ServiceFactory").getCronService().listAll();
The key in the struct containing the task name is "task". So you can extract all the task names as an array for example, run Leigh's function on each element and determine which one will run next.

Boost Filesystem Compile Error

I'm writing some code that utilizes the boost filesystem library. Here is an excerpt of my code:
artist = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? (*(paths_iterator->parent_path().end() - 1)) : (*(paths_iterator->parent_path().end() - 2));
album = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? "" : (*(paths_iterator->parent_path().end() - 1));
Types:
artist and album are of type std::string
this->find_diff returns an int
this->m_input_path is a std::string
paths_iterator is of type std::vector(open bracket)boost::filesystem::path>::iterator
I get a compile error:
error C2039: 'advance' : is not a member of 'boost::filesystem::basic_path<String,Traits>::iterator' d:\development\libraries\boost\boost\iterator\iterator_facade.hpp on line 546
This code is part of a program that outputs a batch script that uses lame.exe to convert files into mp3s.
The music library this is designed for has the format:
root/artist/song
OR
root/artist/album/song
this->m_input_path is the path to root.
I'm not sure if I'm approaching the problem properly. If I am, how do I fix the error that I am getting?
EDIT:
My code is now:
boost::filesystem::path::iterator end_path_itr = paths_iterator->parent_path().end();
if(this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) /* For cases where: /root/artist/song */
{
album = "";
end_path_itr--;
artist = *end_path_itr;
}
else /* For cases where: /root/artist/album/song */
{
end_path_itr--;
album = *end_path_itr;
end_path_itr--; <-- Crash Here
artist = *end_path_itr;
}
The error that I now get is:
Assertion failed: itr.m_pos && "basic_path::iterator decrement pat begin()", file ... boost\filesystem\path.hpp, line 1444
basic_path::iterator is a bidirectional iterator. So arithmetic with -1 and -2 is not allowed. Operators + and - between an iterator and an integer value is defined for a RandomAccessIterator.
Instead of using .end()-1, you could resort to using --.
Your new error indicates that your end_path_iter doesn't have enough elements (should that be "decrement past begin"?), i.e. your path is shorter than you expect.