From 1ab6be9625d473cb564fb16806138204a67151ef Mon Sep 17 00:00:00 2001 From: ahrenholz Date: Wed, 30 Apr 2014 21:27:41 +0000 Subject: [PATCH] fix bug #244 by printing an error when some non-unique directory names are used in the custom_services_dir setting (Boeing r1841) --- daemon/core/service.py | 10 +++++++--- doc/usage.rst | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/daemon/core/service.py b/daemon/core/service.py index a1cd59f3..a4e30a1c 100644 --- a/daemon/core/service.py +++ b/daemon/core/service.py @@ -46,6 +46,9 @@ class CoreServices(ConfigurableManager): ''' _name = "services" _type = coreapi.CORE_TLV_REG_UTILITY + + _invalid_custom_names = ('core', 'addons', 'api', 'bsd', 'emane', 'misc', + 'netns', 'phys', 'services', 'xen') def __init__(self, session): ConfigurableManager.__init__(self, session) @@ -72,10 +75,11 @@ class CoreServices(ConfigurableManager): return try: parentdir, childdir = os.path.split(path) - if childdir == "services": + if childdir in self._invalid_custom_names: raise ValueError, "use a unique custom services dir name, " \ - "not 'services'" - sys.path.append(parentdir) + "not '%s'" % childdir + if not parentdir in sys.path: + sys.path.append(parentdir) exec("from %s import *" % childdir) except Exception, e: self.session.warn("error importing custom services from " \ diff --git a/doc/usage.rst b/doc/usage.rst index a3456b80..352ba54a 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -1640,6 +1640,12 @@ defines the service; then the `custom_services_dir` entry must be set in the :file:`/etc/core/core.conf` configuration file. A sample is provided in the :file:`myservices/` directory. +.. NOTE:: + The directory name used in `custom_services_dir` should be unique and + should not correspond to + any existing Python module name. For example, don't use the name `subprocess` + or `services`. + If you have created a new service type that may be useful to others, please consider contributing it to the CORE project.