mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-23 13:11:21 -05:00
Add cleanup method for the Meek class to kill any meek-client subprocesses once done. Hide stderr from the CLI printed output
This commit is contained in:
parent
c81862130b
commit
3a715346af
@ -286,8 +286,8 @@ def main(cwd=None):
|
|||||||
web = Web(common, False, mode_settings, mode)
|
web = Web(common, False, mode_settings, mode)
|
||||||
|
|
||||||
# Create the Meek object and start the meek client
|
# Create the Meek object and start the meek client
|
||||||
meek = Meek(common)
|
# meek = Meek(common)
|
||||||
meek.start()
|
# meek.start()
|
||||||
|
|
||||||
# Create the CensorshipCircumvention object to make
|
# Create the CensorshipCircumvention object to make
|
||||||
# API calls to Tor over Meek
|
# API calls to Tor over Meek
|
||||||
@ -296,6 +296,8 @@ def main(cwd=None):
|
|||||||
# domain fronting.
|
# domain fronting.
|
||||||
# censorship_recommended_settings = censorship.request_settings(country="cn")
|
# censorship_recommended_settings = censorship.request_settings(country="cn")
|
||||||
# print(censorship_recommended_settings)
|
# print(censorship_recommended_settings)
|
||||||
|
# Clean up the meek subprocess once we're done working with the censorship circumvention API
|
||||||
|
# meek.cleanup()
|
||||||
|
|
||||||
# Start the Onion object
|
# Start the Onion object
|
||||||
try:
|
try:
|
||||||
|
@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ class Meek(object):
|
|||||||
self.meek_front,
|
self.meek_front,
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
startupinfo=startupinfo,
|
startupinfo=startupinfo,
|
||||||
bufsize=1,
|
bufsize=1,
|
||||||
env=self.meek_env,
|
env=self.meek_env,
|
||||||
@ -101,6 +103,7 @@ class Meek(object):
|
|||||||
self.meek_front,
|
self.meek_front,
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
bufsize=1,
|
bufsize=1,
|
||||||
env=self.meek_env,
|
env=self.meek_env,
|
||||||
text=True,
|
text=True,
|
||||||
@ -136,6 +139,40 @@ class Meek(object):
|
|||||||
self.common.log("Meek", "start", "Could not obtain the meek port")
|
self.common.log("Meek", "start", "Could not obtain the meek port")
|
||||||
raise MeekNotRunning()
|
raise MeekNotRunning()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
"""
|
||||||
|
Kill any meek subprocesses.
|
||||||
|
"""
|
||||||
|
self.common.log("Meek", "cleanup")
|
||||||
|
|
||||||
|
if self.meek_proc:
|
||||||
|
self.meek_proc.terminate()
|
||||||
|
time.sleep(0.2)
|
||||||
|
if self.meek_proc.poll() is None:
|
||||||
|
self.common.log(
|
||||||
|
"Meek",
|
||||||
|
"cleanup",
|
||||||
|
"Tried to terminate meek-client process but it's still running",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
self.meek_proc.kill()
|
||||||
|
time.sleep(0.2)
|
||||||
|
if self.meek_proc.poll() is None:
|
||||||
|
self.common.log(
|
||||||
|
"Meek",
|
||||||
|
"cleanup",
|
||||||
|
"Tried to kill meek-client process but it's still running",
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
self.common.log(
|
||||||
|
"Meek", "cleanup", "Exception while killing meek-client process"
|
||||||
|
)
|
||||||
|
self.meek_proc = None
|
||||||
|
|
||||||
|
# Reset other Meek settings
|
||||||
|
self.meek_proxies = {}
|
||||||
|
self.meek_port = None
|
||||||
|
|
||||||
|
|
||||||
class MeekNotRunning(Exception):
|
class MeekNotRunning(Exception):
|
||||||
"""
|
"""
|
||||||
|
@ -264,6 +264,7 @@ class MoatThread(QtCore.QThread):
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
self.meek.cleanup()
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
self.common.log("MoatThread", "run", f"status_code={r.status_code}")
|
self.common.log("MoatThread", "run", f"status_code={r.status_code}")
|
||||||
self.bridgedb_error.emit()
|
self.bridgedb_error.emit()
|
||||||
@ -316,6 +317,7 @@ class MoatThread(QtCore.QThread):
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
self.meek.cleanup()
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
self.common.log("MoatThread", "run", f"status_code={r.status_code}")
|
self.common.log("MoatThread", "run", f"status_code={r.status_code}")
|
||||||
self.bridgedb_error.emit()
|
self.bridgedb_error.emit()
|
||||||
|
Loading…
Reference in New Issue
Block a user