Crates.io | chook |
lib.rs | chook |
version | 0.1.0 |
source | src |
created_at | 2024-06-25 18:29:06.73055 |
updated_at | 2024-06-25 18:29:06.73055 |
description | chook allows injecting code into child processes. For now, it is just a placeholder. |
homepage | |
repository | https://github.com/shell-pool/chook |
max_upload_size | |
id | 1283620 |
size | 14,275 |
chook
(short for Child Hook) is a Rust crate that allows
you to register a fn<ArgT: Deserialize, RetT: Serialize>(arg: ArgT) -> RetT
an inject it into a child process via LD_PRELOAD
.
This allows you to run code in the address space of your child process, which lets you do some things that you can't do otherwise. If you don't control the implementation of the child process, this can let you do such things despite not being able to put any custom code directly into the child process.
In particular, this is used by shpool to update environment variables in child shells.
Your hook routine will get packaged up in a .so
file with an
_init
routine that listens for a few magic env vars that tell
it
It will then create a unix domain socket and start listening for RPC calls, which it will then use to call your registered hook.
When you create a subprocess, you'll be able to register a chook
with the process before launch, and subsequently place calls to
the hook via the same handle that you used for registration.