Sounds like something eBPF would be well suited for. You could install a little program like open();read();close();return and call it with one context...