commit c5a14f99a548c95647653dd293327aac78891979 Author: Kathleen Brade brade@pearlcrescent.com Date: Mon Jul 15 16:50:57 2013 -0700
Use new processID API if available.
This removes the Tor Launcher dependency on JS-Ctypes. --- src/components/tl-process.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/components/tl-process.js b/src/components/tl-process.js index 1ef4d8a..91a5ec2 100644 --- a/src/components/tl-process.js +++ b/src/components/tl-process.js @@ -537,8 +537,24 @@ TorProcessService.prototype =
_getpid: function() { + // Use nsIXULRuntime.processID if it is available. + var pid = 0; + try { + var xreSvc = Cc["@mozilla.org/xre/app-info;1"] + .getService(Ci.nsIXULRuntime); + pid = xreSvc.processID; + } + catch (e) + { + TorLauncherLogger.safelog(2, "failed to get process ID via XUL runtime:", + e); + } + + // Try libc.getpid() via js-ctypes. + if (!pid) try + { var getpid; if (TorLauncherUtil.isMac) { @@ -566,14 +582,14 @@ TorProcessService.prototype = getpid = libc.declare("getpid", ctypes.default_abi, ctypes.int); }
- return getpid(); + pid = getpid(); } catch(e) { TorLauncherLogger.safelog(4, "unable to get process ID: ", e); }
- return 0; + return pid; },
endOfObject: true