[pypy-commit] pypy default: Fix syslog.py by following the CPython source, as per
arigo
noreply at buildbot.pypy.org
Thu Nov 17 14:27:40 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r49494:b6585727903b
Date: 2011-11-17 14:27 +0100
http://bitbucket.org/pypy/pypy/changeset/b6585727903b/
Log: Fix syslog.py by following the CPython source, as per
https://bugs.pypy.org/issue928. Not really tested -- there seems to
be no tests for syslog?
diff --git a/lib_pypy/syslog.py b/lib_pypy/syslog.py
--- a/lib_pypy/syslog.py
+++ b/lib_pypy/syslog.py
@@ -38,9 +38,27 @@
_setlogmask.argtypes = (c_int,)
_setlogmask.restype = c_int
+_S_log_open = False
+_S_ident_o = None
+
+def _get_argv():
+ try:
+ import sys
+ script = sys.argv[0]
+ if isinstance(script, str):
+ return script[script.rfind('/')+1:] or None
+ except Exception:
+ pass
+ return None
+
@builtinify
-def openlog(ident, option, facility):
- _openlog(ident, option, facility)
+def openlog(ident=None, logoption=0, facility=LOG_USER):
+ global _S_ident_o, _S_log_open
+ if ident is None:
+ ident = _get_argv()
+ _S_ident_o = c_char_p(ident) # keepalive
+ _openlog(_S_ident_o, logoption, facility)
+ _S_log_open = True
@builtinify
def syslog(arg1, arg2=None):
@@ -48,11 +66,18 @@
priority, message = arg1, arg2
else:
priority, message = LOG_INFO, arg1
+ # if log is not opened, open it now
+ if not _S_log_open:
+ openlog()
_syslog(priority, "%s", message)
@builtinify
def closelog():
- _closelog()
+ global _S_log_open, S_ident_o
+ if _S_log_open:
+ _closelog()
+ _S_log_open = False
+ _S_ident_o = None
@builtinify
def setlogmask(mask):
More information about the pypy-commit
mailing list