~ruther/guix-local

ee78d02452208b3cfd971cd5533570a1d3523512 — David Thompson 10 years ago 4949ada
build: container: Use the same clone flags as fork(3).

The intent is to make 'clone' behave a lot more like 'primitive-fork', which
calls clone(2) with SIGCHLD, CLONE_CHILD_CLEARTID, and CLONE_CHILD_SETTID
flags.  Notably, running 'clone' at the REPL without these flags would break
the REPL beyond repair.

* guix/build/syscalls.scm (CLONE_CHILD_CLEARTID, CLONE_CHILD_SETTID): New
  variables.
* gnu/build/linux-container.scm (namespaces->bit-mask): Add
  CLONE_CHILD_CLEARTID and CLONE_CHILD_SETTID to bit mask.
2 files changed, 12 insertions(+), 7 deletions(-)

M gnu/build/linux-container.scm
M guix/build/syscalls.scm
M gnu/build/linux-container.scm => gnu/build/linux-container.scm +2 -1
@@ 162,7 162,8 @@ host user identifiers to map into the user namespace."
(define (namespaces->bit-mask namespaces)
  "Return the number suitable for the 'flags' argument of 'clone' that
corresponds to the symbols in NAMESPACES."
  (apply logior SIGCHLD
  ;; Use the same flags as fork(3) in addition to the namespace flags.
  (apply logior SIGCHLD CLONE_CHILD_CLEARTID CLONE_CHILD_SETTID
         (map (match-lambda
               ('mnt  CLONE_NEWNS)
               ('uts  CLONE_NEWUTS)

M guix/build/syscalls.scm => guix/build/syscalls.scm +10 -6
@@ 50,6 50,8 @@
            mkdtemp!
            pivot-root

            CLONE_CHILD_CLEARTID
            CLONE_CHILD_SETTID
            CLONE_NEWNS
            CLONE_NEWUTS
            CLONE_NEWIPC


@@ 303,12 305,14 @@ string TMPL and return its file name.  TMPL must end with 'XXXXXX'."
        (pointer->string result)))))

;; Linux clone flags, from linux/sched.h
(define CLONE_NEWNS   #x00020000)
(define CLONE_NEWUTS  #x04000000)
(define CLONE_NEWIPC  #x08000000)
(define CLONE_NEWUSER #x10000000)
(define CLONE_NEWPID  #x20000000)
(define CLONE_NEWNET  #x40000000)
(define CLONE_CHILD_CLEARTID #x00200000)
(define CLONE_CHILD_SETTID   #x01000000)
(define CLONE_NEWNS          #x00020000)
(define CLONE_NEWUTS         #x04000000)
(define CLONE_NEWIPC         #x08000000)
(define CLONE_NEWUSER        #x10000000)
(define CLONE_NEWPID         #x20000000)
(define CLONE_NEWNET         #x40000000)

;; The libc interface to sys_clone is not useful for Scheme programs, so the
;; low-level system call is wrapped instead.