From: ng0 Date: Wed, 11 Sep 2019 10:56:20 +0000 (+0000) Subject: contrib: gnunet_janitor, terminate: remove win32 functionalities. X-Git-Tag: v0.11.7~122 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d5bd0b9e37d5c5b1bf1c0af6af2dea5ad471b3ce;p=oweals%2Fgnunet.git contrib: gnunet_janitor, terminate: remove win32 functionalities. This commit is questionable, but since I removed win32 code this code no longer has any purpose. --- diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in index 79e32fb90..b0b50ca76 100644 --- a/contrib/scripts/gnunet_janitor.py.in +++ b/contrib/scripts/gnunet_janitor.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -31,24 +31,14 @@ import time import signal import terminate -if os.name == 'nt': - from win32com.client import GetObject - WMI = GetObject('winmgmts:') - - def get_process_list(): result = [] - if os.name == 'nt': - processes = WMI.InstancesOf('Win32_Process') - for p in processes: - result.append((p.Properties_('ProcessId').Value, re.sub(r'(.+)\.exe', r'\1', p.Properties_('Name').Value))) - else: - pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] - for pid in pids: - with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as p: - cmdline = p.read().split('\x00') - if len(cmdline) > 0: - result.append((pid, cmdline[0])) + pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] + for pid in pids: + with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as p: + cmdline = p.read().split('\x00') + if len(cmdline) > 0: + result.append((pid, cmdline[0])) return result diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in index 161b4db61..f57ac6167 100644 --- a/contrib/scripts/terminate.py.in +++ b/contrib/scripts/terminate.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -24,9 +24,6 @@ import sys import subprocess import os -if os.name == 'nt': - import win32api - import win32process class dummyobj (object): @@ -34,35 +31,9 @@ class dummyobj (object): def safe_terminate_process_by_pid(pid, code): - if os.name == 'nt': - p = dummyobj() - p._handle = win32api.OpenProcess(2 | 1024 | 8 | 32 | 16, 0, pid) - result = safe_terminate_process(p, code) - win32api.CloseHandle(p._handle) - return result - else: - # XXX (F821): Undefined name 'SIGKILL' - return os.kill(int(pid), SIGKILL) + # XXX (F821): Undefined name 'SIGKILL' + return os.kill(int(pid), SIGKILL) def safe_terminate_process(proc, code): - if os.name == 'nt': - cp = win32api.GetCurrentProcess() - result = False - dupproc = win32api.DuplicateHandle(cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0) - try: - exitcode = win32process.GetExitCodeProcess(dupproc) - if exitcode == 0x103: - kernel32 = win32api.GetModuleHandle("kernel32") - exitprocess = win32api.GetProcAddress(kernel32, "ExitProcess") - th, tid = win32process.CreateRemoteThread(dupproc, None, 0, exitprocess, code, 0) - win32api.CloseHandle(th) - result = True - else: - result = True - # except failed to get exit code? failed to get module handle? - finally: - win32api.CloseHandle(dupproc) - return result - else: - return proc.kill() + return proc.kill()