Merging Shelter & Msh [weekly-2026-w45]
- November 14, 2026
- Patrick Ferris
This week finally saw the merging of two projects I have been working on: Merry and Shelter. On the surface, the resulting tool might seem quite similar to Shelter, but, in fact, it is much closer to a full POSIX shell than it is to, say, Docker.
Confusingly, the merged project is called Merry. Anyway, here it is in action using a contrived example (using the excellent k7 by Thomas).
Merging shell sessions in Merry
Quite a few libraries I have been working on needed fixing and updating to get to this point.
ZFS bindings
- November 14, 2026
- Patrick Ferris
The first was a set of ZFS bindings I have been working: ocaml-zfs.
I needed to be able to provide some more complicated properties to ZFS pool and dataset creation functions. These come in the form of BSD-style "name-value lists" (nvlist). For example, here's how you might set up a file-backed disk for testing your ZFS tools:
let pool_name = "tank"
let setup_pool handle disk =
let () =
if Sys.file_exists disk then ()
else begin
let () =
let fd = Unix.openfile disk Unix.[ O_CREAT; O_TRUNC ] 0o644 in
Unix.close fd
in
Unix.truncate disk (1024 * 1024 * 128 (* 128MB *))
end
in
let leaf_vdev = [ ("type", `String "file"); ("path", `String disk) ] in
let vdev =
[ ("type", `String "root"); ("children", `Nvlists [ leaf_vdev ]) ]
in
Zfs.Zpool.create ~vdev handle pool_name
Exceptions are now much better than they were previously. Most functions now raise a Zfs_error (kind, msg) if something goes wrong, like trying to open a pool that does not exist:
let () =
let zfs = Zfs.init () in
let pool = Zfs.Zpool.open_ zfs "nope" in
Zfs.Zpool.close pool
(* Fatal error: exception Zfs_error(Noent,"no such pool")*)
Whilst small, these quality of life improvements end up saving time in the long run when Merry breaks or does something incorrect!
User probes in eBPF
- November 14, 2026
- Patrick Ferris
One of the core components of Merry, is an eBPF-based side effect tracer. eBPF supports adding user-space probes. For this to work, eBPF expects programs to define the absolute offset of the symbol they wish to trace inside the program. In practice, this often requires reading shared libraries that are loaded dynamically at runtime. Luckily enough, Thomas has recently developed a pretty easy-to-use Elf parser in OCaml.
The first user-space function I wanted to trace was libc's getenv. Whilst not all libraries and programming languages use it to interact with the process's environment, some do (like OCaml when you call Sys.getenv).
The ostrace tool I wrote (née opentrace) now supports uprobes.
I also updated the open-traces to use the Linux security module (LSM) hooks that eBPF exposes. These are much more likely to catch all open-like calls. Unfortunately, the hook does not contain the same amount of information as tracing the syscalls or uring requests.
let () = print_endline (Sys.getenv "HOME")
When run through ostrace.
$ ostrace ./main.exe pid,cgid,comm,kind,flags,mode,filename,payload,return 167048,666510,"main.exe",lsm,32800,67141633,"/home/patrick/documents/phd/dev/ostrace/_build/default/example/main.exe","",0 167048,666510,"main.exe",lsm,32800,67141633,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/ld-linux-x86-64.so.2","",0 167048,666510,"main.exe",openat,524288,0,"/nix/store/vz2z46bspxsljs79w4zm0qv7r5jaxamq-shell/lib/glibc-hwcaps/x86-64-v3/librt.so.1","",-2 167048,666510,"main.exe",openat,524288,0,"/nix/store/vz2z46bspxsljs79w4zm0qv7r5jaxamq-shell/lib/glibc-hwcaps/x86-64-v2/librt.so.1","",-2 167048,666510,"main.exe",openat,524288,0,"/nix/store/vz2z46bspxsljs79w4zm0qv7r5jaxamq-shell/lib/librt.so.1","",-2 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/glibc-hwcaps/x86-64-v3/librt.so.1","",-2 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/glibc-hwcaps/x86-64-v2/librt.so.1","",-2 167048,666510,"main.exe",lsm,32768,67141633,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/librt.so.1","",0 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/librt.so.1","",3 167048,666510,"main.exe",lsm,32768,67141633,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libm.so.6","",0 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libm.so.6","",3 167048,666510,"main.exe",lsm,32768,67141633,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libpthread.so.0","",0 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libpthread.so.0","",3 167048,666510,"main.exe",lsm,32768,67141633,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6","",0 167048,666510,"main.exe",openat,524288,0,"/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6","",3 167048,666510,"main.exe",getenv,0,0,"OCAMLRUNPARAM","",0 167048,666510,"main.exe",getenv,0,0,"CAMLRUNPARAM","",0 167048,666510,"main.exe",getenv,0,0,"OCAML_RUNTIME_EVENTS_DIR","",0 167048,666510,"main.exe",getenv,0,0,"OCAML_RUNTIME_EVENTS_PRESERVE","",0 167048,666510,"main.exe",getenv,0,0,"OCAML_RUNTIME_EVENTS_START","",0 167048,666510,"main.exe",getenv,0,0,"OCAMLRUNPARAM","",0 167048,666510,"main.exe",getenv,0,0,"CAMLRUNPARAM","",0 167048,666510,"main.exe",getenv,0,0,"HOME","/home/patrick",1
Fork actions for namespaces
- November 14, 2026
- Patrick Ferris
To interact with namespaces, Merry must fork itself. Up until now, forking was only ever used in the fork+exec model for running user programs.
Now, we do fork on every "toplevel" complete command in the shell (roughly equivalent to every line).
Eio contains a useful abstraction called fork actions -- these are non-allocating, little fragments of C-code that get called before a process calls exec to set up the environment in the child process (things like changing the directory, redirecting FDs etc.). We borrow that in void and remove the requirement to call exec. With that removed, it now becomes a way to alter the environment in a forked child that is still running the OCaml program.
For example, the main action we need is a pivot_root.
let actions =
[ Void.Private.Fork_actions.pivot_root ~root (Context.mode ctx) ]
in
We have other support for mapping UIDs, and will need more for setting up the network, resetting the time etc.