summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-06-04 06:27:52 +0300
committerDevaev Maxim <[email protected]>2020-06-04 06:27:52 +0300
commit9cee98310deb851c4a5c36b1e593f032f8234c32 (patch)
tree907d908432c5ce43c729866d67a323daf35aa25e /kvmd
parentbe9ce4e4ffa418ba64612efdabee116dd59a6f5d (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/aioproc.py10
-rw-r--r--kvmd/apps/kvmd/server.py4
-rw-r--r--kvmd/plugins/hid/otg/device.py8
-rw-r--r--kvmd/plugins/hid/serial.py7
4 files changed, 16 insertions, 13 deletions
diff --git a/kvmd/aioproc.py b/kvmd/aioproc.py
index a778141d..4c503bca 100644
--- a/kvmd/aioproc.py
+++ b/kvmd/aioproc.py
@@ -27,6 +27,8 @@ import signal
from typing import Tuple
from typing import List
+import setproctitle
+
# =====
async def run_process(cmd: List[str], err_to_null: bool=False) -> asyncio.subprocess.Process: # pylint: disable=no-member
@@ -34,7 +36,7 @@ async def run_process(cmd: List[str], err_to_null: bool=False) -> asyncio.subpro
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=(asyncio.subprocess.DEVNULL if err_to_null else asyncio.subprocess.STDOUT),
- preexec_fn=preexec_ignore_sigint,
+ preexec_fn=ignore_sigint,
))
@@ -44,5 +46,9 @@ async def read_process(cmd: List[str], err_to_null: bool=False) -> Tuple[asyncio
return (proc, stdout.decode(errors="ignore").strip())
-def preexec_ignore_sigint() -> None:
+def ignore_sigint() -> None:
signal.signal(signal.SIGINT, signal.SIG_IGN)
+
+
+def rename_process(suffix: str, prefix: str="kvmd") -> None:
+ setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}")
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 423e77dc..aa4cd83b 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -37,7 +37,6 @@ from typing import Any
import aiohttp
import aiohttp.web
-import setproctitle
from ...logging import get_logger
@@ -56,6 +55,7 @@ from ...validators.kvm import valid_stream_quality
from ...validators.kvm import valid_stream_fps
from ... import aiotools
+from ... import aioproc
from .auth import AuthManager
from .info import InfoManager
@@ -215,7 +215,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
def run(self, **kwargs: Any) -> None: # type: ignore # pylint: disable=arguments-differ
self.__hid.start()
- setproctitle.setproctitle(f"kvmd/main: {setproctitle.getproctitle()}")
+ aioproc.rename_process("main")
super().run(**kwargs)
async def _make_app(self) -> aiohttp.web.Application:
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py
index d1a2c86c..44c286cb 100644
--- a/kvmd/plugins/hid/otg/device.py
+++ b/kvmd/plugins/hid/otg/device.py
@@ -22,7 +22,6 @@
import os
import select
-import signal
import multiprocessing
import multiprocessing.queues
import queue
@@ -31,11 +30,10 @@ import time
from typing import Dict
-import setproctitle
-
from ....logging import get_logger
from .... import aiomulti
+from .... import aioproc
# =====
@@ -78,8 +76,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
logger = get_logger(0)
logger.info("Started HID-%s pid=%d", self.__name, os.getpid())
- signal.signal(signal.SIGINT, signal.SIG_IGN)
- setproctitle.setproctitle(f"kvmd/hid-{self.__name}: {setproctitle.getproctitle()}")
+ aioproc.ignore_sigint()
+ aioproc.rename_process(f"hid-{self.__name}")
while not self.__stop_event.is_set():
try:
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 0af31eca..6f92d9e4 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -21,7 +21,6 @@
import os
-import signal
import asyncio
import multiprocessing
import multiprocessing.queues
@@ -35,7 +34,6 @@ from typing import Dict
from typing import AsyncGenerator
import serial
-import setproctitle
from ...logging import get_logger
@@ -43,6 +41,7 @@ from ...keyboard.mappings import KEYMAP
from ... import aiotools
from ... import aiomulti
+from ... import aioproc
from ... import gpio
from ...yamlconf import Option
@@ -278,8 +277,8 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
logger = get_logger(0)
logger.info("Started HID pid=%d", os.getpid())
- signal.signal(signal.SIGINT, signal.SIG_IGN)
- setproctitle.setproctitle(f"kvmd/hid: {setproctitle.getproctitle()}")
+ aioproc.ignore_sigint()
+ aioproc.rename_process("hid")
while not self.__stop_event.is_set():
try: