Pier Angelo Vendrame pushed to branch tor-browser-147.0a1-16.0-2 at The Tor Project / Applications / Tor Browser
Commits:
-
14497cc9
by Pier Angelo Vendrame at 2026-02-11T15:30:20+01:00
4 changed files:
- toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs
- toolkit/components/tor-launcher/TorProcess.sys.mjs
- toolkit/components/tor-launcher/TorProcessAndroid.sys.mjs
- toolkit/components/tor-launcher/TorProvider.sys.mjs
Changes:
| ... | ... | @@ -11,6 +11,7 @@ const lazy = {}; |
| 11 | 11 | |
| 12 | 12 | ChromeUtils.defineESModuleGetters(lazy, {
|
| 13 | 13 | FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
|
| 14 | + TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs",
|
|
| 14 | 15 | });
|
| 15 | 16 | |
| 16 | 17 | const kPropBundleURI = "chrome://torbutton/locale/torlauncher.properties";
|
| ... | ... | @@ -699,4 +700,27 @@ export const TorLauncherUtil = { |
| 699 | 700 | console.warn("Could not remove the IPC directory", e);
|
| 700 | 701 | }
|
| 701 | 702 | },
|
| 703 | + |
|
| 704 | + /**
|
|
| 705 | + * Broadcast a tor log message. This message will be visible to the user.
|
|
| 706 | + *
|
|
| 707 | + * NOTE: Users are likely to copy and paste their tor log to forums, etc.
|
|
| 708 | + * Therefore, the messages should avoid containing any information that might
|
|
| 709 | + * identify information about the user.
|
|
| 710 | + *
|
|
| 711 | + * @param {string} type The log type (ERR, WARN, etc...)
|
|
| 712 | + * @param {string} msg The log message
|
|
| 713 | + */
|
|
| 714 | + log(type, msg) {
|
|
| 715 | + const timestamp =
|
|
| 716 | + new Date().toISOString().replace("T", " ").replace("Z", "") + " UTC";
|
|
| 717 | + Services.obs.notifyObservers(
|
|
| 718 | + { type, msg, timestamp },
|
|
| 719 | + lazy.TorProviderTopics.TorLog
|
|
| 720 | + );
|
|
| 721 | + if (type === "WARN" || type === "ERR") {
|
|
| 722 | + // Notify so that Copy Log can be enabled.
|
|
| 723 | + Services.obs.notifyObservers(null, lazy.TorProviderTopics.HasWarnOrErr);
|
|
| 724 | + }
|
|
| 725 | + },
|
|
| 702 | 726 | }; |
| ... | ... | @@ -141,9 +141,18 @@ export class TorProcess { |
| 141 | 141 | this.#status = TorProcessStatus.Exited;
|
| 142 | 142 | this.#subprocess = null;
|
| 143 | 143 | logger.error("startTor error:", e);
|
| 144 | + lazy.TorLauncherUtil.log(
|
|
| 145 | + "PARENT-ERR",
|
|
| 146 | + "Failed to start a tor process (more information in the browser console)."
|
|
| 147 | + );
|
|
| 144 | 148 | throw e;
|
| 145 | 149 | }
|
| 146 | 150 | |
| 151 | + lazy.TorLauncherUtil.log(
|
|
| 152 | + "PARENT-INFO",
|
|
| 153 | + `New tor process started with pid ${this.#subprocess.pid}.`
|
|
| 154 | + );
|
|
| 155 | + |
|
| 147 | 156 | // Do not await the following functions, as they will return only when the
|
| 148 | 157 | // process exits.
|
| 149 | 158 | this.#dumpStdout();
|
| ... | ... | @@ -189,8 +198,15 @@ export class TorProcess { |
| 189 | 198 | const { exitCode } = await watched.wait();
|
| 190 | 199 | processExitCode = exitCode;
|
| 191 | 200 | |
| 201 | + lazy.TorLauncherUtil.log(
|
|
| 202 | + exitCode !== 0 ? "PARENT-WARN" : "PARENT-INFO",
|
|
| 203 | + `The tor process with pid ${this.#subprocess.pid} exited with code ${exitCode}.`
|
|
| 204 | + );
|
|
| 205 | + |
|
| 192 | 206 | if (watched !== this.#subprocess) {
|
| 193 | - logger.debug(`A Tor process exited with code ${exitCode}.`);
|
|
| 207 | + logger.debug(
|
|
| 208 | + `The tor process ${watched.pid} exited with code ${exitCode}.`
|
|
| 209 | + );
|
|
| 194 | 210 | } else if (exitCode) {
|
| 195 | 211 | logger.warn(`The watched Tor process exited with code ${exitCode}.`);
|
| 196 | 212 | } else {
|
| ... | ... | @@ -6,6 +6,7 @@ const lazy = {}; |
| 6 | 6 | |
| 7 | 7 | ChromeUtils.defineESModuleGetters(lazy, {
|
| 8 | 8 | EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
|
| 9 | + TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs",
|
|
| 9 | 10 | });
|
| 10 | 11 | |
| 11 | 12 | const logger = console.createInstance({
|
| ... | ... | @@ -107,6 +108,27 @@ export class TorProcessAndroid { |
| 107 | 108 | }
|
| 108 | 109 | |
| 109 | 110 | onEvent(event, data, _callback) {
|
| 111 | + switch (event) {
|
|
| 112 | + case TorIncomingEvents.started:
|
|
| 113 | + lazy.TorLauncherUtil.log(
|
|
| 114 | + "PARENT-INFO",
|
|
| 115 | + `New tor process with handle ${data.handle} started.`
|
|
| 116 | + );
|
|
| 117 | + break;
|
|
| 118 | + case TorIncomingEvents.startFailed:
|
|
| 119 | + lazy.TorLauncherUtil.log(
|
|
| 120 | + "PARENT-ERR",
|
|
| 121 | + `Failed to start a tor process: ${data.error}`
|
|
| 122 | + );
|
|
| 123 | + break;
|
|
| 124 | + case TorIncomingEvents.exited:
|
|
| 125 | + lazy.TorLauncherUtil.log(
|
|
| 126 | + data.status !== 0 ? "PARENT-WARN" : "PARENT-INFO",
|
|
| 127 | + `The tor process with handle ${data.handle} exited with status ${data.status}.`
|
|
| 128 | + );
|
|
| 129 | + break;
|
|
| 130 | + }
|
|
| 131 | + |
|
| 110 | 132 | if (data?.handle !== this.#processHandle) {
|
| 111 | 133 | logger.debug(`Ignoring event ${event} with another handle`, data);
|
| 112 | 134 | return;
|
| ... | ... | @@ -207,8 +207,15 @@ export class TorProvider { |
| 207 | 207 | await this.#firstConnection();
|
| 208 | 208 | } catch (e) {
|
| 209 | 209 | logger.error("Cannot connect to the control port", e);
|
| 210 | + // Log this also to the UI, as getting console logs from Android
|
|
| 211 | + // makes troubleshooting more difficult and involved.
|
|
| 212 | + TorLauncherUtil.log(
|
|
| 213 | + "PARENT-ERR",
|
|
| 214 | + `Connection to the control port failed: ${e.message}.`
|
|
| 215 | + );
|
|
| 210 | 216 | throw e;
|
| 211 | 217 | }
|
| 218 | + TorLauncherUtil.log("PARENT-INFO", "Connected to the control port.", false);
|
|
| 212 | 219 | |
| 213 | 220 | if (this.ownsTorDaemon) {
|
| 214 | 221 | try {
|
| ... | ... | @@ -1021,21 +1028,7 @@ export class TorProvider { |
| 1021 | 1028 | * @param {string} msg The message
|
| 1022 | 1029 | */
|
| 1023 | 1030 | onLogMessage(type, msg) {
|
| 1024 | - if (type === "WARN" || type === "ERR") {
|
|
| 1025 | - // Notify so that Copy Log can be enabled.
|
|
| 1026 | - Services.obs.notifyObservers(null, TorProviderTopics.HasWarnOrErr);
|
|
| 1027 | - }
|
|
| 1028 | - |
|
| 1029 | - const timestamp = new Date()
|
|
| 1030 | - .toISOString()
|
|
| 1031 | - .replace("T", " ")
|
|
| 1032 | - .replace("Z", "");
|
|
| 1033 | - |
|
| 1034 | - Services.obs.notifyObservers(
|
|
| 1035 | - { type, msg, timestamp },
|
|
| 1036 | - TorProviderTopics.TorLog
|
|
| 1037 | - );
|
|
| 1038 | - |
|
| 1031 | + TorLauncherUtil.log(type, msg);
|
|
| 1039 | 1032 | switch (type) {
|
| 1040 | 1033 | case "ERR":
|
| 1041 | 1034 | logger.error(`[Tor error] ${msg}`);
|