This evening I wrote a chunk of code that, given a PID, goes and does the chdir() and chroot() calls on it to a given directory. That process suddenly finds itself isolated while it’s running. It’s kind of like pulling the carpet pulled out from under it, but so quickly it doesn’t notice.
In other words, I’m kidnapping a process, and stuffing it into a chroot.
Now, for some processes this will cause it to error out in all kinds of interesting ways, because it’ll then not be able to find files they need. But for processes that already have all their file descriptors open – and no intention of opening anything else – it’s a great way to stuff it into a container without having to do all the tedious steps to setup a proper chroot environment.
I’m having way too much fun with this.
If this code actually turns out to not cause weird behavior on the process(es) I’m targeting, I’ll publish the code, and why I’m doing this along with it. In the mean time, roll your eyes and shrug your shoulders.