From 641e7e1835171434f434c2e0a02e9c308bc7df9c Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Thu, 26 Sep 2013 13:29:01 -0700 Subject: [PATCH] avoid calling locale. treat ps output as bytes until we get a progname if progname won't decode, we don't know it anyway. --- configure-syslog.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/configure-syslog.py b/configure-syslog.py index 73f15c2..0b10dd1 100755 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -33,7 +33,6 @@ import socket import subprocess from optparse import OptionParser, SUPPRESS_HELP -import locale import traceback #Constants @@ -556,15 +555,18 @@ def find_syslog_process(): if results: #For python version 3 and above, reading binary data, not str, #so we need to decode the output first: - encoding = locale.getdefaultlocale()[1] or 'UTF-8' - reslines = results.decode(encoding).split('\n') + reslines = results.split(b'\n') if len(reslines) == 1: ps_out_fields = reslines[0].split() pid = int(ps_out_fields[1]) progname = ps_out_fields[7] - if '/' in progname: - progname = progname.split('/')[-1] - return (progname, pid) + if b'/' in progname: + progname = progname.split(b'/')[-1] + try: + return (progname.decode('UTF-8'), pid) + except ValueError: + # if progname won't decode, it's not a progname we know. + pass return None, 0 def check_syslog_service_status(syslog_type):