From b26f349d681c60cdad4c4dbde0ea6adfbe7d741a Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Fri, 1 Oct 2010 02:41:38 +0200 Subject: [PATCH] Add sys.argv. Not too many programs consider the possibility that it might not exist resulting in unhandled exceptions. --- src/collectd-python.pod | 10 ++++++++++ src/python.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/collectd-python.pod b/src/collectd-python.pod index 45a06d1d..cbfd2672 100644 --- a/src/collectd-python.pod +++ b/src/collectd-python.pod @@ -1,3 +1,13 @@ +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + =head1 NAME collectd-python - Documentation of collectd's C diff --git a/src/python.c b/src/python.c index 384ca8b7..16de81d4 100644 --- a/src/python.c +++ b/src/python.c @@ -892,6 +892,7 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) { static int cpy_config(oconfig_item_t *ci) { int i; + char *argv = ""; PyObject *sys, *tb; PyObject *sys_path; PyObject *module; @@ -921,6 +922,9 @@ static int cpy_config(oconfig_item_t *ci) { cpy_log_exception("python initialization"); return 1; } + PySys_SetArgv(1, &argv); + PyList_SetSlice(sys_path, 0, 1, NULL); + module = Py_InitModule("collectd", cpy_methods); /* Borrowed reference. */ PyModule_AddObject(module, "Config", (void *) &ConfigType); /* Steals a reference. */ PyModule_AddObject(module, "Values", (void *) &ValuesType); /* Steals a reference. */ -- 2.30.2