File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -735,17 +735,22 @@ def initialize
735735    end 
736736
737737    def  address_from_file 
738-       f  =  File . new ( "/var/lib/dbus/machine-id" ) 
739-       machine_id  =  f . readline . chomp 
740-       f . close 
741-       display  =  ENV [ "DISPLAY" ] . gsub ( /.*:([0-9]*).*/ ,  '\1' ) 
742-       File . open ( ENV [ "HOME" ]  + "/.dbus/session-bus/#{ machine_id }  -#{ display }  " ) . each  do  |line |
738+       # systemd uses /etc/machine-id 
739+       # traditional dbus uses /var/lib/dbus/machine-id 
740+       machine_id_path  =  Dir [ '{/etc,/var/lib/dbus}/machine-id' ] . first 
741+       return  nil  unless  machine_id_path 
742+       machine_id  =  File . read ( machine_id_path ) . chomp 
743+ 
744+       display  =  ENV [ "DISPLAY" ] . gsub ( /.*:([0-9]*)\. */ ,  '\1' ) 
745+ 
746+       bus_file_path  =  File . join ( ENV [ "HOME" ] ,  "/.dbus/session-bus/#{ machine_id }  -#{ display }  " ) 
747+       return  nil  unless  File . exists? ( bus_file_path ) 
748+ 
749+       File . open ( bus_file_path ) . lines  do  |line |
743750        if  line  =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/ 
744751          return  $1
745752        end 
746753      end 
747-     rescue  Errno ::ENOENT 
748-       nil 
749754    end 
750755  end 
751756
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments