Skip to content

Improve DBUS_SESSION_BUS_ADDRESS extraction #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

grauwoelfchen
Copy link
Contributor

Hi :-D

I've got following error after update of dbus (system dbus, not ruby-dbus)

% bundle exec ruby -e 'require "dbus"; DBus::SessionBus.instance'               
/path/to/gems/ruby/2.3.0/gems/ruby-dbus-0.11.1/lib/dbus/message_queue.rb:46:in `push': undefined method `write' for nil:NilClass (NoMethodError)
        from /path/to/gems/ruby/2.3.0/gems/ruby-dbus-0.11.1/lib/dbus/bus.rb:442:in `send_sync'
        from /path/to/gems/ruby/2.3.0/gems/ruby-dbus-0.11.1/lib/dbus/bus.rb:582:in `send_hello'
        from /path/to/gems/ruby/2.3.0/gems/ruby-dbus-0.11.1/lib/dbus/bus.rb:601:in `initialize'        from /path/to/ruby/2.3.0/singleton.rb:142:in `new'                      
        from /path/to/ruby/2.3.0/singleton.rb:142:in `block in instance'        
        from /path/to/ruby/2.3.0/singleton.rb:140:in `synchronize'              
        from /path/to/ruby/2.3.0/singleton.rb:140:in `instance'                    
        from -e:1:in `<main>'

The cause of this error was DBUS_SESSION_BUS_ADDRESS value surrounded by single quotation from generated file in ~/.dbus/session-bus/#{MACHINE_ID}-#{ENV["DISPLAY"]}

% cat ~/.dbus/session-bus/MACHINE_ID-0 
# This file allows processes on the machine with id MACHINE_ID using 
# display :0.0 to find the D-Bus session bus with the below address.
# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will
# be used rather than this file.
# See "man dbus-launch" for more details.
DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-foo,guid=12345...'
DBUS_SESSION_BUS_PID=...
DBUS_SESSION_BUS_WINDOWID=...

If I remove this single quotations from this file, then error has gone.
But I think that It would might be better to support it in ruby-dbus.

Then I've just created this pull request ;)
How dou you think about this?

I tested this change in ruby {2.3.1|1.9.3-p551|2.0.0-p648} in local.
If I need some thing change about code or style, please tell me.

especially, I used some mocks at rspec instead of real file for testing or Tempfile.

Improvement

  • Add support DBUS_SESSION_BUS_ADDRESS value surrounded by quotation marks (' and ")

Environment

The OS on my latop is Gentoo Linux.

% uname -a
Linux HOSTNAME 4.5.2-gentoo #18 SMP Sun Aug 7 14:23:24 CEST 2016 x86_64 Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz GenuineIntel GNU/Linux

The dbus version is 1.10.10

% dbus-launch --version
D-Bus Message Bus Launcher 1.10.10
Copyright (C) 2003 Red Hat, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm using dbus without user session support.
And it is compiled for 32 bit and 64 bit both.

% eix sys-apps/dbus
[I] sys-apps/dbus
     Available versions:  1.8.16 (~)1.8.20 1.10.8-r1^t (~)1.10.10^t {X debug doc selinux static-libs systemd test user-session ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  1.10.10^t(11:15:09 PM 09/03/2016)(X -debug -doc -selinux -static-libs -systemd -test -user-session ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            https://dbus.freedesktop.org/
     Description:         A message bus system, a simple way for applications to talk to each other

I'm using ruby-dbus 0.11.1 on ruby {2.3.1|1.9.3-p551|2.0.0-p648} :)

% bundle list | grep dbus
  * ruby-dbus (0.11.1)

thanks

Add support for such value surrounded by quotation marks as:

* DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-foo,guid=123'
* DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-foo,guid=123"
@coveralls
Copy link

coveralls commented Sep 4, 2016

Coverage Status

Changes Unknown when pulling 67aa6ef on grauwoelfchen:fix-dbus-session-bus-address-extraction into * on mvidner:master*.

@grauwoelfchen
Copy link
Contributor Author

grauwoelfchen commented Sep 4, 2016

@mvidner
The job on CI fails for problem of json and tins version
https://travis-ci.org/mvidner/ruby-dbus/jobs/157432617

I was able to run tests fine on ruby 1.9.3 with following Gemfile:

source "http://rubygems.org"

# ruby-1.9.3p551
if RUBY_VERSION =~ /\A1\.9/
  gem "json", "1.8.0"
  gem "tins", "1.6.0"
end

gem "rake"
gem "packaging_rake_tasks"
gem "nokogiri"
gem "rspec"
gem "simplecov"
gem "coveralls"
platforms :rbx do
  gem "racc"
end

@grauwoelfchen
Copy link
Contributor Author

I've also created pull request #63 for test failure for ruby 1.9.3 on ci :)

@mvidner
Copy link
Owner

mvidner commented Sep 6, 2016

Thank you for the detailed report, and the fix, and the tests!

The dbus behavior changed with the release of 1.10.10:

Output valid shell syntax in ~/.dbus/session-bus/ if the bus address contains a semicolon (fd.o #94746, Thiago Macieira)

@mvidner mvidner merged commit 67aa6ef into mvidner:master Sep 6, 2016
@grauwoelfchen
Copy link
Contributor Author

Oh, I didn't notice mentioned this entry on release note. thanks!

@grauwoelfchen
Copy link
Contributor Author

And, ah, I had to use ENV["DBUS_SESSION_BUS_ADDRESS"] as it is...
Thank you for your improvements ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants