Paste number 148860: call-with-container

Paste number 148860: call-with-container
Pasted by: davexunit
When:6 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+36V0
Channel:None
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")
                       mount-points))
      (chroot root-dir)
      (chdir "/")
      (thunk))))

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.