initPlugins: run nix_plugin_entry() on dlopen'd plugins

Only when it exists.
This commit is contained in:
Yorick van Pelt 2023-08-07 15:41:21 +02:00 committed by José Luis Lafuente
parent 713f10aeaa
commit dc0f7d8f96
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A

View file

@ -346,6 +346,12 @@ void initPlugins()
dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle)
throw Error("could not dynamically open plugin file '%s': %s", file, dlerror());
/* Older plugins use a statically initialized object to run their code.
Newer plugins can also export nix_plugin_entry() */
void (*nix_plugin_entry)() = (void (*)())dlsym(handle, "nix_plugin_entry");
if (nix_plugin_entry)
nix_plugin_entry();
}
}