GithubHelp home page GithubHelp logo

p5-protocol-dbus's People

Contributors

fgasper avatar manwar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

manwar potatogim

p5-protocol-dbus's Issues

Error while running Protocol::DBus::Client example code

$cat dbus.pl
#!/usr/bin/perl

use strict;
use warnings;


use Carp::Always;
use Protocol::DBus;
use Protocol::DBus::Client;


my $dbus = Protocol::DBus::Client::system();

$dbus->do_authn();

$dbus->send_call(
    method => 'org.freedesktop.DBus.Properties.GetAll',
    signature => 's',
    path => '/org/freedesktop/DBus',
    destination => 'org.freedesktop.DBus',
    body => [ 'org.freedesktop.DBus' ],
    callback => sub { my ($msg) = @_ },
);
$ ./dbus.pl
Can't locate object method "buf" via package "Socket::MsgHdr" at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Socket/MsgHdr.pm line 87.
	Socket::MsgHdr::new("Socket::MsgHdr", "buf", "\x{0}") called at /usr/local/share/perl/5.24.1/Protocol/DBus/Authn/Mechanism/EXTERNAL.pm line 48
	Protocol::DBus::Authn::Mechanism::EXTERNAL::send_initial(Protocol::DBus::Authn::Mechanism::EXTERNAL=HASH(0x5560c934d8b0), GLOB(0x5560c91b6170)) called at /usr/local/share/perl/5.24.1/Protocol/DBus/Authn.pm line 95
	Protocol::DBus::Authn::go(Protocol::DBus::Authn=HASH(0x5560c9405600)) called at /usr/local/share/perl/5.24.1/Protocol/DBus/Client.pm line 94
	Protocol::DBus::Client::do_authn(Protocol::DBus::Client=HASH(0x5560c947c6b8)) called at ./dbus.pl line 14
$ perl -v
perl -v

This is perl 5, version 24, subversion 1 (v5.24.1) built for x86_64-linux-gnu-thread-multi
(with 81 registered patches, see perl -V for more detail)

Copyright 1987-2017, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
$ perl -MSocket::MsgHdr -e 'print $Socket::MsgHdr::VERSION'
0.04

Fix UNIX_FD support

Receive:

  • Switch to recvmsg().
  • Collect each SCM_RIGHTS control message received.
  • (Verify the header for number of descriptors?)
  • get_filehandle( $INDEX ) method of Protocol::DBus::Message
  • Message object needs to store FHs internally so that cleanup happens

Send:

  • methods to accept filehandles array (FDs/FHs)
  • Use sendmsg()

Inconsistent use of $self->{_paused} between Protocol::DBus::Client::Mojo and ::EventBase

When trying Protocol::DBus::Client::Mojo together with Mojo::Reactor::Prima, an inconsistency in the use of
$self->{_paused} manifested itself in a crash:

Mojo::Reactor::Prima: I/O watcher failed: Can't use an undefined value as a SCALAR reference at /home/corion/perl5/lib/perl5/Protocol/DBus/Client/Mojo.pm line 174.

Unfortunately, I can't reproduce this in a smaller, self-contained program yet, but visual inspection of line 174 of lib/Protocol/DBus/Client/Mojo.pm resp. the line initializing $paused_r shows this:

my $paused_r = $self->{'_paused'};

This feels wrong since $paused_r should be a reference to the _paused key and is also used as such. A similiar piece of code in ::EventBase shows use as a reference:

sub initialize {
    my ($self) = @_;

    my $paused_sr = \$self->{'_paused'};

    my $dbus = $self->{'db'};
    ...

Changing the line to a reference makes the problem go away:

my $paused_r = \$self->{'_paused'};

But even with that change, in the larger program, the DBus promises never get resolved when the Mojo::Reactor::Prima event loop is used.

The program works with only Mojolicious and DBus alone, but I'm at a loss to see where the Mojo::IOLoop is different from the Mojo::Reactor::Prima, or to understand what special things DBus needs from the io-loop that Prima does not provide.

I've attached a not-so-short self-contained example program to reproduce the problem. The program passes with $mojo_reactor_prima set to 0, but fails with $mojo_reactor_prima set to 1.

Maybe you have an idea?

prima-dbus-interaction.pl.txt

Dependencies aren't pure perl (Socket::MsgHdr)

While it's true that your module is Pure Perl, the Socket::MsgHdr dependency isn't. By itself that's not a problem, however, there doesn't seem to be a Pure Perl fallback.

More precisely, I'm running one of the submitted examples (called dbus.pl on my system) through App::FatPacker and I'm getting this output:

 $ fatpack pack dbus.pl > fat-dbus.pl
dbus.pl syntax OK
File /home/ehuelsmannfatlib/perl/5.24.1/auto/Socket/MsgHdr/MsgHdr.so isn't a .pm file - can't pack this -- if you hoped we were going to, things may not be what you expected later
 at /usr/share/perl5/App/FatPacker.pm line 251.

D-bus connection closes, promise error/finally not called

I think I have a pretty minimal test script to send a dbus notification from an IO::Async loop. When I run the script I get this warning from ::Parser but my Promise error block doesn't get called and my loop hangs because the Promise's finally callback doesn't trigger.

D-Bus connection closed unexpectedly! at .../Protocol/DBus/Parser.pm line 28.

Trying to diagnose the problem and see what is written to the dbus socket, I ran the script with strace and it runs successfully! The notification displays correctly and I can access the return value of the dbus call in the promise sequence.

There has to be a timing issue at play, right?

$ perl ./dbus-send.pl
D-Bus connection closed unexpectedly! at .../Protocol/DBus/Parser.pm line 28.
^C

$ strace -e write=3,4 -e read=3,4 -e send,sendto,recv,recvfrom -e abbrev=none perl dbus-send.pl
... 
ok!
id is 4824
Full strace
$ perl ./dbus-send.pl
D-Bus connection closed unexpectedly! at .../Protocol/DBus/Parser.pm line 28.
^C

$ strace -e write=3,4 -e read=3,4 -e send,sendto,recv,recvfrom -e abbrev=none perl dbus-send.pl
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377789, si_uid=1000, si_status=1, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377790, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377793, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377794, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377799, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=377802, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
sendto(3, "l\1\0\1\0\0\0\0\1\0\0\0n\0\0\0\2\1s\0\24\0\0\0org.free"..., 128, MSG_NOSIGNAL, NULL, 0) = 128
 | 00000  6c 01 00 01 00 00 00 00  01 00 00 00 6e 00 00 00  l...........n... |
 | 00010  02 01 73 00 14 00 00 00  6f 72 67 2e 66 72 65 65  ..s.....org.free |
 | 00020  64 65 73 6b 74 6f 70 2e  44 42 75 73 00 00 00 00  desktop.DBus.... |
 | 00030  06 01 73 00 14 00 00 00  6f 72 67 2e 66 72 65 65  ..s.....org.free |
 | 00040  64 65 73 6b 74 6f 70 2e  44 42 75 73 00 00 00 00  desktop.DBus.... |
 | 00050  03 01 73 00 05 00 00 00  48 65 6c 6c 6f 00 00 00  ..s.....Hello... |
 | 00060  01 01 6f 00 15 00 00 00  2f 6f 72 67 2f 66 72 65  ..o...../org/fre |
 | 00070  65 64 65 73 6b 74 6f 70  2f 44 42 75 73 00 00 00  edesktop/DBus... |
recvfrom(3, 0x559d590f6c90, 16, MSG_PEEK, 0x7ffc29059ac0, [4096]) = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(3, "l\2\1\1\r\0\0\0\1\0\0\0E\0\0\0", 16, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 16
 | 00000  6c 02 01 01 0d 00 00 00  01 00 00 00 45 00 00 00  l...........E... |
recvfrom(3, "l\2\1\1\r\0\0\0\1\0\0\0E\0\0\0\6\1s\0\10\0\0\0:1.89823"..., 88, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 88
 | 00000  6c 02 01 01 0d 00 00 00  01 00 00 00 45 00 00 00  l...........E... |
 | 00010  06 01 73 00 08 00 00 00  3a 31 2e 38 39 38 32 33  ..s.....:1.89823 |
 | 00020  00 00 00 00 00 00 00 00  05 01 75 00 01 00 00 00  ..........u..... |
 | 00030  08 01 67 00 01 73 00 00  07 01 73 00 14 00 00 00  ..g..s....s..... |
 | 00040  6f 72 67 2e 66 72 65 65  64 65 73 6b 74 6f 70 2e  org.freedesktop. |
 | 00050  44 42 75 73 00 00 00 00                           DBus....         |
sendto(3, "l\1\0\1|\0\0\0\2\0\0\0\237\0\0\0\2\1s\0\35\0\0\0org.free"..., 300, MSG_NOSIGNAL, NULL, 0) = 300
 | 00000  6c 01 00 01 7c 00 00 00  02 00 00 00 9f 00 00 00  l...|........... |
 | 00010  02 01 73 00 1d 00 00 00  6f 72 67 2e 66 72 65 65  ..s.....org.free |
 | 00020  64 65 73 6b 74 6f 70 2e  4e 6f 74 69 66 69 63 61  desktop.Notifica |
 | 00030  74 69 6f 6e 73 00 00 00  06 01 73 00 1d 00 00 00  tions.....s..... |
 | 00040  6f 72 67 2e 66 72 65 65  64 65 73 6b 74 6f 70 2e  org.freedesktop. |
 | 00050  4e 6f 74 69 66 69 63 61  74 69 6f 6e 73 00 00 00  Notifications... |
 | 00060  03 01 73 00 06 00 00 00  4e 6f 74 69 66 79 00 00  ..s.....Notify.. |
 | 00070  08 01 67 00 0d 73 75 73  73 73 61 73 61 7b 73 76  ..g..susssasa{sv |
 | 00080  7d 69 00 00 00 00 00 00  01 01 6f 00 1e 00 00 00  }i........o..... |
 | 00090  2f 6f 72 67 2f 66 72 65  65 64 65 73 6b 74 6f 70  /org/freedesktop |
 | 000a0  2f 4e 6f 74 69 66 69 63  61 74 69 6f 6e 73 00 00  /Notifications.. |
 | 000b0  0d 00 00 00 4c 65 61 72  6e 59 6f 75 41 44 62 75  ....LearnYouADbu |
 | 000c0  73 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  s............... |
 | 000d0  12 00 00 00 4e 6f 74 69  66 20 23 20 31 36 34 39  ....Notif # 1649 |
 | 000e0  34 35 33 37 38 32 00 00  33 00 00 00 54 68 69 73  453782..3...This |
 | 000f0  20 69 73 20 6e 6f 74 69  66 69 63 61 74 69 6f 6e   is notification |
 | 00100  20 23 20 31 36 34 39 34  35 33 37 38 32 20 66 72   # 1649453782 fr |
 | 00110  6f 6d 20 64 62 75 73 2d  73 65 6e 64 2e 70 6c 00  om dbus-send.pl. |
 | 00120  00 00 00 00 00 00 00 00  10 27 00 00              .........'..     |
recvfrom(3, "l\4\1\1\r\0\0\0\2\0\0\0\225\0\0\0", 16, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 16
 | 00000  6c 04 01 01 0d 00 00 00  02 00 00 00 95 00 00 00  l............... |
recvfrom(3, "l\4\1\1\r\0\0\0\2\0\0\0\225\0\0\0\1\1o\0\25\0\0\0/org/fre"..., 168, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 168
 | 00000  6c 04 01 01 0d 00 00 00  02 00 00 00 95 00 00 00  l............... |
 | 00010  01 01 6f 00 15 00 00 00  2f 6f 72 67 2f 66 72 65  ..o...../org/fre |
 | 00020  65 64 65 73 6b 74 6f 70  2f 44 42 75 73 00 00 00  edesktop/DBus... |
 | 00030  02 01 73 00 14 00 00 00  6f 72 67 2e 66 72 65 65  ..s.....org.free |
 | 00040  64 65 73 6b 74 6f 70 2e  44 42 75 73 00 00 00 00  desktop.DBus.... |
 | 00050  03 01 73 00 0c 00 00 00  4e 61 6d 65 41 63 71 75  ..s.....NameAcqu |
 | 00060  69 72 65 64 00 00 00 00  06 01 73 00 08 00 00 00  ired......s..... |
 | 00070  3a 31 2e 38 39 38 32 33  00 00 00 00 00 00 00 00  :1.89823........ |
 | 00080  08 01 67 00 01 73 00 00  07 01 73 00 14 00 00 00  ..g..s....s..... |
 | 00090  6f 72 67 2e 66 72 65 65  64 65 73 6b 74 6f 70 2e  org.freedesktop. |
 | 000a0  44 42 75 73 00 00 00 00                           DBus....         |
recvfrom(3, 0x559d590f6c90, 16, MSG_PEEK, 0x7ffc29059ac0, [4096]) = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(3, "l\2\1\1\4\0\0\0\7_\0\0006\0\0\0", 16, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 16
 | 00000  6c 02 01 01 04 00 00 00  07 5f 00 00 36 00 00 00  l........_..6... |
recvfrom(3, "l\2\1\1\4\0\0\0\7_\0\0006\0\0\0\6\1s\0\10\0\0\0:1.89823"..., 72, MSG_PEEK, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, [4096->21]) = 72
 | 00000  6c 02 01 01 04 00 00 00  07 5f 00 00 36 00 00 00  l........_..6... |
 | 00010  06 01 73 00 08 00 00 00  3a 31 2e 38 39 38 32 33  ..s.....:1.89823 |
 | 00020  00 00 00 00 00 00 00 00  08 01 67 00 01 75 00 00  ..........g..u.. |
 | 00030  05 01 75 00 02 00 00 00  07 01 73 00 05 00 00 00  ..u.......s..... |
 | 00040  3a 31 2e 35 33 00 00 00                           :1.53...         |
ok!
id is 4824
recvfrom(3, 0x559d590f6c90, 16, MSG_PEEK, 0x7ffc29059ac0, [4096]) = -1 EAGAIN (Resource temporarily unavailable)
+++ exited with 0 +++
dbus-send.pl
use 5.32.0; use warnings;
use experimental 'signatures';

use IO::Async::Loop;
use Protocol::DBus::Client::IOAsync;
use Promise::ES6::Future;

my $loop = IO::Async::Loop->new;
my $dbus = Protocol::DBus::Client::IOAsync::login_session($loop);

$dbus->initialize
->then(sub ($dbus) {
   my $id = time;
   return $dbus->send_call(
      path => '/org/freedesktop/Notifications',
      interface => 'org.freedesktop.Notifications',
      member => 'Notify',
      destination => 'org.freedesktop.Notifications',
      signature => 'susssasa{sv}i',

      body => [
         'LearnYouADbus', # appname
         0, '',           # id, icon
         "Notif # $id",   # summary
         "This is notification # $id from $0", # body
         [], {},          # actions, hints
         1000*10,         # timeout ms
      ],
   );
})
->then(sub ($res, @){
   say "ok!";
   if ($res->isa('Protocol::DBus::Message')) {
      my ($id) = $res->get_body->@*;
      say "id is $id";
      return $id;
   }
}, sub ($err, @){
   say "error! $err";
})
->finally(sub { $loop->stop });

$loop->run;

Not receiving signals

Thanks to the quick follow-up on #2, I'm now able to run connections oven DBus and send method_calls and receive responses. However, I'm not receiving signals. I have tried to understand the code, but don't understand where they could be lost.

Running the code below gives me a several hundreds signals such as this one on dbus-monitor:

signal time=1541933260.081834 sender=:1.57 -> destination=(null destination) serial=880648 path=/42_caecdadc; interface=org.freedesktop.PackageKit.Transaction; member=Package
   uint32 2
   string "zzuf;0.15-1+b1;amd64;debian-stable-main"
   string "transparent application fuzzer"

My code doesn't receive one of them though. The for loop gets stuck and the only message I see is the one which is the response to the initial GetPackages method_call.

(Note that the code below assumes your system has PackageKit installed.)

#!/usr/bin/perl

use strict;
use warnings;


#use Carp::Always;
use Data::Dumper;
use Socket::MsgHdr;
use Protocol::DBus;
use Protocol::DBus::Client;


my $dbus = Protocol::DBus::Client::system();

$dbus->do_authn();

$dbus->get_message();

$dbus->send_call(
    member => 'CreateTransaction',
    signature => '',
    path => '/org/freedesktop/PackageKit',
    destination => 'org.freedesktop.PackageKit',
    interface => 'org.freedesktop.PackageKit',
);

my $trans_path = shift @{$dbus->get_message()->get_body()};

$dbus->send_call(
    member => 'GetPackages',
    signature => 't',
    path => $trans_path,
    destination => 'org.freedesktop.PackageKit',
    interface => 'org.freedesktop.PackageKit.Transaction',
    body => [ 2 ],
);

for my $i (1 .. 100) {
my $msg = $dbus->get_message();

print Dumper $msg;
}

I'd love to help resolve this, but don't know where to start in your code or in the DBus spec... (Most info I'm finding concerns the GLib DBus bindings, not DBus itself...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.