Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the optional feature to specify module_path using mosquitto config #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

viraja1
Copy link

@viraja1 viraja1 commented Aug 7, 2017

Optional feature to specify module_path using mosquitto config. If mosquitto broker is run using service, then PYTHONPATH is not available. e.g. sudo service mosquitto start. The service removes all environment variables including PYTHONPATH.

@@ -157,6 +161,9 @@ int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth
die(false, "failed to initialize auxiliary module");
#endif

if(data->module_path != NULL){
PySys_SetPath(data->module_path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gripe with PySys_SetPath is that it replaces sys.path completely with new value. It's unintuitive for any user used to PYTHONPATH environment variable, which extends default path instead of replacing it. A C version of following code would be preferable:

import sys
sys.path.insert(0, data->module_path.split(':'))

If you feel like implementing it, then go ahead. Otherwise, ping me and I'll merge your PR and add my own fix on top of it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relacing PySys_SetPath(data->module_path);

with

PyObject *sys = PyImport_ImportModule("sys");
PyObject *path = PyObject_GetAttrString(sys, "path");
PyList_Append(path, PyString_FromString(data->module_path));

yields the result you're after.

I got that code from here https://stackoverflow.com/a/8859538/277267 and checked if it works

/ # mosquitto -c /mosquitto/config/mosquitto.conf
1547320203: mosquitto version 1.5.5 starting
1547320203: Config loaded from /mosquitto/config/mosquitto.conf.
1547320203: plugin_init (opts: ((u'pyauth_module_append_path', u'/mosquitto/scripts'),))
['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/pyt hon2.7/lib-dynload', '/usr/lib/python2.7/site-packages', '/mosquitto/scripts']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants