diff options
author | Matthew Johnson <mjj29@qadesh.matthew.ath.cx> | 2009-11-01 12:45:35 +0000 |
---|---|---|
committer | Matthew Johnson <mjj29@qadesh.matthew.ath.cx> | 2009-11-01 12:45:35 +0000 |
commit | d49879de16c25757e4d6be0a5338f062c069bedb (patch) | |
tree | 36c4c3aa8d5bd28703b5deb63cde3fa37aaf24e7 /org | |
parent | 53e9b6f78197c0d9041d4429b1c5e6ec1b90386f (diff) |
read bus address from /home/mjj29
Diffstat (limited to 'org')
-rw-r--r-- | org/freedesktop/dbus/DBusConnection.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java index e2b6d7d..6262bf5 100644 --- a/org/freedesktop/dbus/DBusConnection.java +++ b/org/freedesktop/dbus/DBusConnection.java @@ -14,6 +14,9 @@ import static org.freedesktop.dbus.Gettext._; import java.lang.reflect.Proxy; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.text.MessageFormat; @@ -235,7 +238,35 @@ public class DBusConnection extends AbstractConnection break; case SESSION: s = System.getenv("DBUS_SESSION_BUS_ADDRESS"); - if (null == s) throw new DBusException(_("Cannot Resolve Session Bus Address")); + if (null == s) { + // address gets stashed in $HOME/.dbus/session-bus/`dbus-uuidgen --get`-`sed 's/:\(.\)\..*/\1/' <<< $DISPLAY` + String display = System.getenv("DISPLAY"); + if (null == display) throw new DBusException(_("Cannot Resolve Session Bus Address")); + File uuidfile = new File("/var/lib/dbus/machine-id"); + if (!uuidfile.exists()) throw new DBusException(_("Cannot Resolve Session Bus Address")); + try { + BufferedReader r = new BufferedReader(new FileReader(uuidfile)); + String uuid = r.readLine(); + String homedir = System.getProperty("user.home"); + File addressfile = new File(homedir + "/.dbus/session-bus", + uuid + "-" + display.replaceAll(":([0-9]*)\\..*", "$1")); + if (!addressfile.exists()) throw new DBusException(_("Cannot Resolve Session Bus Address")); + r = new BufferedReader(new FileReader(addressfile)); + String l; + while (null != (l = r.readLine())) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Reading D-Bus session data: "+l); + if (l.matches("DBUS_SESSION_BUS_ADDRESS.*")) { + s = l.replaceAll("^[^=]*=", ""); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Parsing "+l+" to "+s); + } + } + if (null == s || "".equals(s)) throw new DBusException(_("Cannot Resolve Session Bus Address")); + if (Debug.debug) Debug.print(Debug.INFO, "Read bus address "+s+" from file "+addressfile.toString()); + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(_("Cannot Resolve Session Bus Address")); + } + } break; default: throw new DBusException(_("Invalid Bus Type: ")+bustype); |