0
0
Fork 0
forked from lix-project/lix

Merge pull request from shlevy/plugin-dirs

Enable specifying directories in plugin-files.
This commit is contained in:
Eelco Dolstra 2018-02-13 17:32:32 +01:00 committed by GitHub
commit 7253113fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions
doc/manual/command-ref
src/libstore

View file

@ -764,6 +764,10 @@ builtins.fetchurl {
should not be linked to any Nix libs directly, as those will should not be linked to any Nix libs directly, as those will
be available already at load time. be available already at load time.
</para> </para>
<para>
If an entry in the list is a directory, all files in the
directory are loaded as plugins (non-recursively).
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View file

@ -142,12 +142,24 @@ void MaxBuildJobsSetting::set(const std::string & str)
void initPlugins() void initPlugins()
{ {
for (const auto & pluginFile : settings.pluginFiles.get()) { for (const auto & pluginFile : settings.pluginFiles.get()) {
Paths pluginFiles;
try {
auto ents = readDirectory(pluginFile);
for (const auto & ent : ents)
pluginFiles.emplace_back(pluginFile + "/" + ent.name);
} catch (SysError & e) {
if (e.errNo != ENOTDIR)
throw;
pluginFiles.emplace_back(pluginFile);
}
for (const auto & file : pluginFiles) {
/* handle is purposefully leaked as there may be state in the /* handle is purposefully leaked as there may be state in the
DSO needed by the action of the plugin. */ DSO needed by the action of the plugin. */
void *handle = void *handle =
dlopen(pluginFile.c_str(), RTLD_LAZY | RTLD_LOCAL); dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle) if (!handle)
throw Error(format("could not dynamically open plugin file '%1%': %2%") % pluginFile % dlerror()); throw Error("could not dynamically open plugin file '%s%': %s%", file, dlerror());
}
} }
} }