From 66b0b96426c370297d2dbbafae3ec337954deb95 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 12 May 2018 00:23:45 +0200 Subject: [PATCH] set application name to fenrir --- src/fenrirscreenreader/core/fenrirManager.py | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/fenrirManager.py b/src/fenrirscreenreader/core/fenrirManager.py index 5254bf9e..9f2a885a 100644 --- a/src/fenrirscreenreader/core/fenrirManager.py +++ b/src/fenrirscreenreader/core/fenrirManager.py @@ -4,7 +4,7 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import signal, time, argparse +import signal, time, argparse, sys from fenrirscreenreader.core import i18n from fenrirscreenreader.core import settingsManager @@ -32,6 +32,7 @@ class fenrirManager(): self.command = '' self.controlMode = True self.switchCtrlModeOnce = 0 + self.setProcessName() def handleArgs(self): args = None parser = argparse.ArgumentParser(description="Fenrir Help") @@ -212,7 +213,32 @@ class fenrirManager(): if self.environment['runtime']['inputManager'].noKeyPressed(): self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) self.command = '' + def setProcessName(self, name = 'fenrir'): + """Attempts to set the process name to 'fenrir'.""" + #sys.argv[0] = name + + # Disabling the import error of setproctitle. + # pylint: disable-msg=F0401 + try: + from setproctitle import setproctitle + except ImportError: + pass + else: + setproctitle(name) + return True + + try: + from ctypes import cdll, byref, create_string_buffer + libc = cdll.LoadLibrary('libc.so.6') + stringBuffer = create_string_buffer(len(name) + 1) + stringBuffer.value = bytes(name, 'UTF-8') + libc.prctl(15, byref(stringBuffer), 0, 0, 0) + return True + except: + pass + + return False def shutdownRequest(self): try: self.environment['runtime']['eventManager'].stopMainEventLoop()