Paste number 148860: call-with-container

Paste number 148860: call-with-container
Pasted by: davexunit
When:6 years, 6 months ago
Share:Tweet this! |
Paste contents:
Raw Source | XML | Display As
(define (call-with-container root-dir mount-points thunk)
  "Run THUNK in a new container process with ROOT-DIR as \"/\" and
MOUNT-POINTS mounted within."
  (define (in-root dir)
    (string-append root-dir dir))

  (let ((new-proc (in-root "/proc"))
        (new-dev  (in-root "/dev"))
        (new-sys  (in-root "/sys")))
    ;; FIXME: User namespaces do not work yet
    (with-clone (delq 'user %all-namespaces)
      (mkdir-p new-proc)
      (mkdir-p new-dev)
      (mkdir-p new-sys)
      (for-each mount
                (cons* (make-mount-point "proc" new-proc "proc")
                       (make-mount-point "dev"  new-dev  "devtmpfs")
                       (make-mount-point "sys"  new-sys  "sysfs")
      (chroot root-dir)
      (chdir "/")

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.