diff --git a/rhn-client-tools.spec b/rhn-client-tools.spec index 4197d2ffde..e6f0bbbc40 100644 --- a/rhn-client-tools.spec +++ b/rhn-client-tools.spec @@ -5,7 +5,7 @@ Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar. URL: https://fedorahosted.org/spacewalk Name: rhn-client-tools Version: 2.0.2 -Release: 8%{?dist} +Release: 9%{?dist} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch %if 0%{?suse_version} @@ -361,6 +361,12 @@ make -f Makefile.rhn-client-tools test %endif %changelog +* Mon Mar 06 2017 Gennadii Altukhov 2.0.2-9 +- Resolves: #1371871 - fix UnicodeDecodeError when running rhnreg_ks with a + different locale than en_US (galt@redhat.com) +- fix except to be compatible with Python 2.4 (galt@redhat.com) +- 1260527,1409570 - Reboot loop - rhn_check, rhnsd (jdostal@redhat.com) + * Fri Jul 22 2016 Tomas Kasparek 2.0.2-8 - Resolves: #1313607 - update strings for RHEL 7.3 (tkasparek@redhat.com) diff --git a/src/bin/rhn_check.py b/src/bin/rhn_check.py index ebe282cba4..0f882dbff8 100755 --- a/src/bin/rhn_check.py +++ b/src/bin/rhn_check.py @@ -48,23 +48,40 @@ from up2date_client import config from up2date_client import clientCaps from up2date_client import capabilities from up2date_client import rhncli, rhnserver - +import signal +from rhn import SSL from rhn import rhnLockfile -import xmlrpclib +from rhn.i18n import bstr, sstr +from rhn.tb import raise_with_tb + +import base64 +import time + +try: # python2 + import xmlrpclib +except ImportError: # python3 + import xmlrpc.client as xmlrpclib + long = int + +del sys.modules['sgmlop'] cfg = config.initUp2dateConfig() log = up2dateLog.initLog() - # action version we understand ACTION_VERSION = 2 +# Stop execution of future actions +TERMINATE = False + +# SystemExit exception error code +SYSEXIT_CODE = 3 + # lock file to check if we're disabled at the server's request DISABLE_FILE = "/etc/sysconfig/rhn/disable" # Actions that will run each time we execute. LOCAL_ACTIONS = [("packages.checkNeedUpdate", ("rhnsd=1",))] - class CheckCli(rhncli.RhnCli): def __init__(self): @@ -189,6 +206,7 @@ class CheckCli(rhncli.RhnCli): sys.exit(1) self.handle_action(action) + action = self.__get_action(status_report) def __verify_server_capabilities(self, caps): @@ -251,6 +269,8 @@ class CheckCli(rhncli.RhnCli): if not cache_only: log.log_debug("Sending back response", (status, message, data)) ret = self.submit_response(action['id'], status, message, data) + if TERMINATE: + sys.exit(0) return ret @@ -345,6 +365,23 @@ class CheckCli(rhncli.RhnCli): def __run_action(method, params, kwargs={}): try: (status, message, data) = CheckCli.__do_call(method, params, kwargs) + except SystemExit: + e = sys.exc_info()[1] + global TERMINATE + TERMINATE = True + # Are we dealing with shutdown script? If yes, send some response + # to server ASAP + if e.code == SYSEXIT_CODE: + extras = { + 'output': '', + 'base64enc': 0, + 'return_code': 0, + 'process_start': '', + 'process_end': '' + } + for key in ('process_start', 'process_end'): + extras[key] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) + return 0, "Script executed. Termination signal occurred during execution", extras except getMethod.GetMethodException: log.log_debug("Attempt to call an unsupported action ", method, params) diff --git a/src/up2date_client/up2dateLog.py b/src/up2date_client/up2dateLog.py index 6daa77205c..1c2d1086e0 100644 --- a/src/up2date_client/up2dateLog.py +++ b/src/up2date_client/up2dateLog.py @@ -4,6 +4,39 @@ import time import config import traceback +from sys import version_info + +try: + PY3 = version_info.major >= 3 +except AttributeError: + PY3 = False + + +def ustr(obj): + # converts object to unicode like object + if PY3: # python3 + if isinstance(obj, str): + return obj + else: + return str(obj, 'utf8', errors='ignore') + else: # python2 + if isinstance(obj, unicode): + return obj + return unicode(obj, 'utf8', 'ignore') + + +def sstr(obj): + # converts object to string + if PY3: # python3 + if isinstance(obj, str): + return obj + else: + return str(obj, 'utf8', errors='ignore') + else: # python2 + if isinstance(obj, str): + return obj + return str(obj.encode('utf8', 'ignore')) + class Log: """ @@ -30,10 +63,9 @@ class Log: self.log_info = "[%s] %s" % (time.ctime(time.time()), self.app) s = u"" for i in args: - if not isinstance(i, unicode): - # we really need unicode(str(i)) here, because i can be anything - # from string or int to list, dict or even class - i = unicode(str(i), 'utf-8') + # we really need unicode(str(i)) here, because i can be anything + # from string or int to list, dict or even class + i = ustr(str(i)) s += i if self.cfg["debug"] > 1: print s @@ -57,8 +89,8 @@ class Log: log_name = self.cfg["logFile"] or "/var/log/up2date" log_file = open(log_name, 'a') - msg = u"%s %s\n" % (self.log_info, s) - log_file.write(msg.encode('utf-8')) + msg = u"%s %s\n" % (ustr(self.log_info), ustr(s)) + log_file.write(sstr(msg)) log_file.flush() log_file.close()