Once the application has been started, it is still possible to make changes in the execution environment, given that both loading and bind manipulation facilities are available through the interface of the DI runtime. By means of these dynamic facilities, we can design lightweight extensions to watch for some conditions before activating new functionality. At run time, these extensions can also deactivate the new service dynamically.
Let us suppose that we have installed an optimized read path for files with read-only access. The following code illustrates how to deactivate the optimization when conditions change. The wrapper has been installed to be activated in response to references to `open()'. It checks for the O_RDONLY flag, and deinstalls the new paths when a file is opened with flags that can compromise the extension:
int rdopen_wrapper(char *file, int flags) { if (flags&O_RDONLY) di_rebind("program","read", "extension","rdo_read"); else di_rebind("program","read", "extension","rdwr_read"); return(open(file, flags)); }
The DITOOLS interface provides rebinding, symbol redefinition, interrogation about current bindings and loaded modules, among other operations. This interface is described in more detail in a research report [18].