[systemd-devel] How to set time from Perl
Daniel P. Berrange
berrange at redhat.com
Mon Sep 7 07:51:37 PDT 2015
On Mon, Sep 07, 2015 at 04:23:42PM +0200, Manuel Reimer wrote:
> Hello,
>
> if I run the following code on an intel based platform, then I don't have
> any problems:
>
> use Net::DBus;
> my $bus = Net::DBus->system();
> my $logind = $bus->get_service('org.freedesktop.timedate1');
> my $manager = $logind->get_object('/org/freedesktop/timedate1',
> 'org.freedesktop.timedate1');
> $manager->SetTime($time * 1000000, 0, 0);
>
> The variable "$time" is in seconds.
>
> If I run this to an ARM based system, then I get the folowing time:
>
> # date
> Thu Jan 1 01:00:02 CET 1970
>
> Does someone have an idea why this doesn't work?
By "ARM system" do you mean 32-bit ArmV7, or 64-bit AArch64 ?
Based on the behaviour you describe, I'm thinking you are most
likely on 32-bit ArmV7. Perl integers on 32-bit are only 32-bit
in length, and the SetTime() method needs a 64-bit integer,
since it is representing the time in microseconds. So when you
do $time * 1000000 you are probably getting integer truncation.
Net::DBus can deal with 64-bit integers, but you need to provide
them as the Perl string type, not integer type, so Net::DBus XS
module can do a safe conversion to 64-bit without truncation.
So instead of doing
$manager->SetTime($time * 1000000, 0, 0);
try doing
$manager->SetTime($time . "000000", 0, 0);
which will conmvert $time to string type, and then append 6
zeros.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the systemd-devel
mailing list