Search guides and the APICtrl K
  1. API reference
  2. Hosting plugins

plugin_cache.h

Remembering what a scan found, and what killed it.

#include <sonore/plugin_cache.h>
On this page

Design notes

Scanning a plugin folder means LOADING SOMEBODY ELSE'S CODE. Every file in it gets dlopened, its entry point called, its factory walked. That is slow (a full folder is seconds), and it is dangerous, because one plugin that faults on load takes the whole host down with it, every single time, and the user has no way to get past it.

Two problems, and the second is the interesting one.

SLOW is solved by writing down what was found and checking timestamps: a file that has not changed since it was scanned does not need scanning again.

CRASHING is solved by a dead man's switch. The path being scanned is written to the cache and FLUSHED TO DISK before the file is opened. If the process dies inside that load, the entry is still sitting there next time, and a plugin that was mid-scan when the host last died is a plugin that killed it. It goes on the blacklist and is not tried again.

That trick is the whole reason this can work in-process. The alternative (scanning in a child process, as some hosts do) is more robust and costs a second binary, an IPC protocol and a lifetime to get wrong. This costs one fflush.

Types 2

What a file looked like when it was scanned. Size and modification time together, because either alone is fooled by something ordinary: a rebuild that lands on the same size, or an installer that preserves timestamps.

What previous scans found, and what they must not try again.

The file format is one record per line, tab separated, with a version on the first line. Not JSON and not binary: a user whose host will not start because of a cache should be able to open it in a text editor and see which plugin is the problem, and delete one line rather than the lot.

Functions 8

↑↓ to move↵ to openEvery public name in the headers, and every guide