more python/pmrep issues with string.replace("foo", None)
"Mark Goodwin" <[email protected]>
| Newsgroups | gmane.comp.sysutils.pcp |
|---|---|
| Message-ID | <[email protected]> |
Hi Marko, I've tracked down the apparent cause of the segfaults I'm seeing
occasionally to another case of somestring.replace(None), which newer
python3 doesn't seem to like, e.g. :
$ python3 ./pmrep.py -s 1 -i '"1 minute",wrong,"5 minute"' --archive
./archives/20130706 -z -O 30m kernel.all.load,,"1 minute",,,16
Traceback (most recent call last):
File "./pmrep.py", line 1615, in <module>
P = PMReporter()
File "./pmrep.py", line 188, in __init__
self.config = self.set_config_file()
File "./pmrep.py", line 383, in set_config_file
conf = conf.replace("$PCP_SYSCONF_DIR", os.getenv("PCP_SYSCONF_DIR"))
TypeError: Can't convert 'NoneType' object to str implicitly
In this case os.getenv("PCP_SYSCONF_DIR") is returning None. This sometimes
ends up with a segfault, but not always (haven't tracked down why exactly).
A reasonable (?) patch seems to be to use the @static method
pmGetConfig('PCP_SYSCONF_DIR') here instead, which will still honor that
variable if it's in the environment, else get it from /etc/pcp.conf, which
resolves to /etc/pcp on most platforms, and so by default we properly load
/etc/pcp/pmrep/pmrep.conf.
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index 2168a54..fd2fb8c 100755
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -380,7 +380,7 @@ class PMReporter(object):
config = DEFAULT_CONFIG[0]
for conf in DEFAULT_CONFIG:
conf = conf.replace("$HOME", os.getenv("HOME"))
- conf = conf.replace("$PCP_SYSCONF_DIR",
os.getenv("PCP_SYSCONF_DIR"))
+ conf = conf.replace("$PCP_SYSCONF_DIR",
pmapi.pmContext.pmGetConfig("PCP_SYSCONF_DIR"))
if os.path.isfile(conf) or os.access(conf, os.R_OK):
config = conf
break