Skip to content

Add PANDA_PLUGIN_PATH#1408

Open
be32826 wants to merge 11 commits into
devfrom
panda-plugin-path
Open

Add PANDA_PLUGIN_PATH#1408
be32826 wants to merge 11 commits into
devfrom
panda-plugin-path

Conversation

@be32826

@be32826 be32826 commented Jan 5, 2024

Copy link
Copy Markdown
Contributor

Add a colon-separated PANDA_PLUGIN_PATH environment variable for specifying plugin directories similar to PATH, PYTHONPATH, and LD_LIBRARY_PATH.

@be32826 be32826 marked this pull request as draft January 6, 2024 04:27
@be32826 be32826 marked this pull request as ready for review January 9, 2024 16:48

@jamcleod jamcleod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall design question: using some combination of PANDA_PATH and PANDA_PLUGIN_DIR depending on needs has been the way of handling this usecase in the past. Is there a reason we're making a new variable with overlapping usecases rather than fixing the previous implementation?

The main differences I see here are:

  • supports providing multiple paths (beneficial, but I don't think requires adding a new environment variable)
  • supports absolute paths (the current code does support this, albeit inconsistently and definitely has bugs for usecases I haven't personally considered. however to me this would be a reason to fix the current code rather than)

This is mostly coming from a place of wanting to avoid having 5 different ways of doing this, each with their own little bugs, with documentation being unclear which one to use. It's also possible that incrementally deprecating the old system is the correct move, all up for consideration.

not saying these are reasons not to merge, just questions worth considering before merging. also be sure to notify me when the design has been ironed out so I can ensure panda-rs also receives a corresponding update.

plugin_name_ffi = self.ffi.new("char[]", bytes(plugin_name, "utf-8"))
plugin_path_ffi = self.libpanda.panda_plugin_path(plugin_name_ffi)
plugin_path = self.ffi.string(plugin_path_ffi).decode("utf-8")
# TODO: self.libpanda.g_free(plugin_path_ffi)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

leftover TODO comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure this is a memory leak without the free, but CFFI doesn't seem to find the g_free() function, which is weird because other parts of the code find g_malloc0(). I don't know what's going on here.

else:
raise ValueError(f"Could not find plugin path. Build dir={build_dir}")
return self.plugin_path
def get_plugin_path(self, plugin_name):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this doesn't seem to cover all the cases from before, was the /usr/local/bin special-casing redundant? it also doesn't appear to perform error propagation/checking, so this is a breaking change (as catching ValueError to handle missing plugins isn't possible)

Comment thread panda/src/callbacks.c
gchar *plugin_path = attempt_normalize_path(g_strdup_printf(
"%s/%s/%s", *dir,
TARGET_NAME, name_formatted));
if (TRUE == g_file_test(plugin_path, G_FILE_TEST_EXISTS)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor nit but don't think you need to actually check against glibc TRUE here. just checking for non-zero return is a superset of checking for glib TRUE, so there's no real reason to write in this style.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can change it but all the other tests in the function use the same style so it would feel inconsistent.

@be32826

be32826 commented Jan 10, 2024

Copy link
Copy Markdown
Contributor Author

Overall design question: using some combination of PANDA_PATH and PANDA_PLUGIN_DIR depending on needs has been the way of handling this usecase in the past. Is there a reason we're making a new variable with overlapping usecases rather than fixing the previous implementation?

Mostly because I'm afraid of breaking backwards compatibility and I don't know how all the different cases apply to how PANDA is used in practice. Do you think it would be better to make PANDA_PLUGIN_DIR support colon-separated multiple directories instead?

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.

2 participants