Skip to content

Commit

Permalink
Enable specifying directories in plugin-files.
Browse files Browse the repository at this point in the history
  • Loading branch information
shlevy committed Feb 13, 2018
1 parent f471aac commit 99562cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/manual/command-ref/conf-file.xml
Expand Up @@ -764,6 +764,10 @@ builtins.fetchurl {
should not be linked to any Nix libs directly, as those will
be available already at load time.
</para>
<para>
If an entry in the list is a directory, all files in the
directory are loaded as plugins (non-recursively).
</para>
</listitem>

</varlistentry>
Expand Down
24 changes: 18 additions & 6 deletions src/libstore/globals.cc
Expand Up @@ -142,12 +142,24 @@ void MaxBuildJobsSetting::set(const std::string & str)
void initPlugins()
{
for (const auto & pluginFile : settings.pluginFiles.get()) {
/* handle is purposefully leaked as there may be state in the
DSO needed by the action of the plugin. */
void *handle =
dlopen(pluginFile.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle)
throw Error(format("could not dynamically open plugin file '%1%': %2%") % pluginFile % dlerror());
Paths pluginFiles;
try {
auto ents = readDirectory(pluginFile);
for (auto & ent : ents)
pluginFiles.emplace_back(pluginFile + std::move(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
DSO needed by the action of the plugin. */
void *handle =
dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle)
throw Error(format("could not dynamically open plugin file '%1%': %2%") % file % dlerror());
}
}
}

Expand Down

0 comments on commit 99562cd

Please sign in to comment.