From 8950ed11c6a0d51be056b3509f3ab269787696e9 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 31 May 2015 20:26:47 -0400 Subject: build: syscalls: Add clone. * guix/build/syscalls.scm (clone): New procedure. (CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWUSER, CLONE_NEWPID, CLONE_NEWNET): New variables. * tests/syscalls.scm ("clone"): New test. --- guix/build/syscalls.scm | 33 +++++++++++++++++++++++++++++++++ tests/syscalls.scm | 15 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index a464040e56..cff010648a 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -47,6 +47,14 @@ processes mkdtemp! + CLONE_NEWNS + CLONE_NEWUTS + CLONE_NEWIPC + CLONE_NEWUSER + CLONE_NEWPID + CLONE_NEWNET + clone + IFF_UP IFF_BROADCAST IFF_LOOPBACK @@ -280,6 +288,31 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'." (list err))) (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) + +;; The libc interface to sys_clone is not useful for Scheme programs, so the +;; low-level system call is wrapped instead. +(define clone + (let* ((ptr (dynamic-func "syscall" (dynamic-link))) + (proc (pointer->procedure int ptr (list int int '*))) + ;; TODO: Don't do this. + (syscall-id (match (utsname:machine (uname)) + ("i686" 120) + ("x86_64" 56) + ("mips64" 5055) + ("armv7l" 120)))) + (lambda (flags) + "Create a new child process by duplicating the current parent process. +Unlike the fork system call, clone accepts FLAGS that specify which resources +are shared between the parent and child processes." + (proc syscall-id flags %null-pointer)))) + ;;; ;;; Packed structures. diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 049ca93267..4bc6f0332c 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -76,6 +76,21 @@ (rmdir dir) #t)))) +(define (user-namespace pid) + (string-append "/proc/" (number->string pid) "/ns/user")) + +(test-assert "clone" + (match (clone (logior CLONE_NEWUSER SIGCHLD)) + (0 (primitive-exit 42)) + (pid + ;; Check if user namespaces are different. + (and (not (equal? (readlink (user-namespace pid)) + (readlink (user-namespace (getpid))))) + (match (waitpid pid) + ((_ . status) + (= 42 (status:exit-val status)))))))) + + (test-assert "all-network-interfaces" (match (all-network-interfaces) (((? string? names) ..1) -- cgit v1.2.3 cc8810264bdc7d2'>gnu: Add python-pytest-tornasync....Ricardo Wurmus 2021-08-30gnu: Add python-pytest-console-scripts....Ricardo Wurmus 2021-08-30gnu: Add python-dna-features-viewer....Ricardo Wurmus 2021-09-18import: Add 'generic-git' updater....Xinglu Chen 8-30gnu: Add python-pybbi....Ricardo Wurmus 2021-08-30gnu: wine: Update to 6.16....Leo Prikler 2021-08-30gnu: Add h-client....Denis 'GNUtoo' Carikli 2021-08-30gnu: wine: Update to 6.14....Leo Prikler 2021-08-30gnu: Add ocaml-odoc-parser....Xinglu Chen 2021-08-30gnu: scrot: Update to 1.6....Ludovic Courtès 2021-08-30build: Build (gnu packages rocm)....Ludovic Courtès 2021-08-30services: hurd-vm: Use the new 'targets' field of <bootloader-configuration>....Ludovic Courtès 2021-08-30bootloader: Report location of the deprecated 'target' field....Ludovic Courtès 2021-08-30build: Build (gnu system setuid)....Ludovic Courtès 2021-08-30gnu: extra-cmake-modules: Avoid dependency on qtbase when on armhf....Ludovic Courtès 2021-08-30services: xorg: Delay the xorg-configuration-modules field evaluation....Mathieu Othacehe 2021-08-30gnu: guile-websocket: Update to 0.1-d17878f6....Jan (janneke) Nieuwenhuizen 2021-08-29gnu: Add emacs-helm-xref....Pierre Langlois 2021-08-29gnu: mu: Update to 1.6.5....Pierre Langlois 2021-08-29gnu: shadow: Use the cross-compiled shell at runtime....Mathieu Othacehe 2021-08-29gnu: Add emacs-hideshowvis....Oleg Pykhalov 2021-08-29gnu: rofi: Update to 1.7.0....Brice Waegeneire 2021-08-29isc-dhcp: Fix dhclient-script wrapper when cross-compiling....Maxime Devos 2021-08-29services: Remove i486 qemu target....Efraim Flashner 2021-08-29services: base: Honor file-system-create-mount-point? at all times....Maxim Cournoyer 2021-08-29gnu: python-pytest-django: Update to 4.4.0....Maxim Cournoyer 2021-08-29gnu: python-django: Update to 3.2.6....Maxim Cournoyer 2021-08-29gnu: ansible: Update to 4.4.0....Maxim Cournoyer 2021-08-29gnu: Add ansible-core....Maxim Cournoyer 2021-08-29gnu: Add python-pytest-xdist-next....Maxim Cournoyer 2021-08-29gnu: python-pytest-xdist: Fix by downgrading to 1.34.0, run test suite....Maxim Cournoyer 2021-08-29gnu: python-pytest-mock: Update to 3.6.1 and run test suite....Maxim Cournoyer 2021-08-29gnu: python-pytest-asyncio: Enable tests and patch for Python 3.8....Maxim Cournoyer 2021-08-29gnu: python-pytest-forked: Update to 1.3.0 and run test suite....Maxim Cournoyer 2021-08-29gnu: python-py-next: Update to 1.10.0....Maxim Cournoyer 2021-08-29gnu: python-mock: Update description....Maxim Cournoyer 2021-08-29gnu: python-rope: Update to 0.19.0 and remove python2-rope....Maxim Cournoyer 2021-08-29gnu: python-execnet: Update to 1.9.0 and enable tests....Maxim Cournoyer 2021-08-29gnu: python-pytest-6: Update to 6.2.4 and propagate iniconfig....Maxim Cournoyer 2021-08-29gnu: Add python-pyspnego....Maxim Cournoyer 2021-08-29gnu: Add python-ncclient....Maxim Cournoyer 2021-08-29gnu: Add python-resolvelib-0.5....Maxim Cournoyer 2021-08-29gnu: Add python-resolvelib....Maxim Cournoyer 2021-08-29gnu: Add python-commentjson....Maxim Cournoyer 2021-08-29Migrate to the new 'targets' field of bootloader-configuration....Maxim Cournoyer 2021-08-29gnu: bootloader: Support multiple targets....Maxim Cournoyer 2021-08-29gnu: Add emacs-company-org-block....Oleg Pykhalov 2021-08-28images: pinebook-pro: Fix the agetty baud rate....Mathieu Othacehe