Skip to content
Browse files

support /etc/machine-id

  • Loading branch information...
1 parent bc62bdd commit 48c4ba3d36e4f17507da64accf64043c942c2dcf @quark-zju quark-zju committed Nov 19, 2012
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/dbus/bus.rb
View
19 lib/dbus/bus.rb
@@ -735,17 +735,22 @@ def initialize
end
def address_from_file
- f = File.new("/var/lib/dbus/machine-id")
- machine_id = f.readline.chomp
- f.close
- display = ENV["DISPLAY"].gsub(/.*:([0-9]*).*/, '\1')
- File.open(ENV["HOME"] + "/.dbus/session-bus/#{machine_id}-#{display}").each do |line|
+ # systemd uses /etc/machine-id
+ # traditional dbus uses /var/lib/dbus/machine-id
+ machine_id_path = Dir['{/etc,/var/lib/dbus}/machine-id'].first
+ return nil unless machine_id_path
+ machine_id = File.read(machine_id_path).chomp
+
+ display = ENV["DISPLAY"].gsub(/.*:([0-9]*)\.*/, '\1')
+
+ bus_file_path = File.join(ENV["HOME"], "/.dbus/session-bus/#{machine_id}-#{display}")
+ return nil unless File.exists?(bus_file_path)
+
+ File.open(bus_file_path).lines do |line|
if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
return $1
end
end
- rescue Errno::ENOENT
- nil
end
end

0 comments on commit 48c4ba3

Please sign in to comment.
Something went wrong with that request. Please try again.