From ae5c6f5d834aff4af1fd3a7c26267b297692c019 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Tue, 18 Mar 2014 16:31:39 +0100 Subject: [redshift-gtk] Add BSD support to proc title setting --- src/redshift-gtk/utils.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/redshift-gtk/utils.py b/src/redshift-gtk/utils.py index 4d3b619..73c95a9 100644 --- a/src/redshift-gtk/utils.py +++ b/src/redshift-gtk/utils.py @@ -67,12 +67,23 @@ def set_autostart(active): def setproctitle(title): - try: - libc = ctypes.cdll.LoadLibrary("libc.so.6") - except OSError: - return - buf = ctypes.create_string_buffer(title.encode(sys.getdefaultencoding())) - try: - libc.prctl(15, ctypes.byref(buf), 0, 0, 0) - except AttributeError: - return # Strange libc, just skip this + title_bytes = title.encode(sys.getdefaultencoding(), 'replace') + buf = ctypes.create_string_buffer(title_bytes) + if 'linux' in sys.platform: + try: + libc = ctypes.cdll.LoadLibrary("libc.so.6") + except OSError: + return + try: + libc.prctl(15, buf, 0, 0, 0) + except AttributeError: + return # Strange libc, just skip this + elif 'bsd' in sys.platform: + try: + libc = ctypes.cdll.LoadLibrary("libc.so.7") + except OSError: + return + try: + libc.setproctitle(ctypes.create_string_buffer(b"-%s"), buf) + except AttributeError: + return -- cgit v1.2.3-70-g09d2