From: David Thompson <dthompson2@worcester.edu>
To: guix-devel@gnu.org
Cc: David Thompson <davet@gnu.org>
Subject: [PATCH 07/15] build: syscalls: Add pivot-root.
Date: Mon, 6 Jul 2015 09:16:36 -0400 [thread overview]
Message-ID: <1436188604-2813-7-git-send-email-dthompson2@worcester.edu> (raw)
In-Reply-To: <1436188604-2813-1-git-send-email-dthompson2@worcester.edu>
From: David Thompson <davet@gnu.org>
* guix/build/syscalls.scm (pivot-root): New procedure.
* tests/syscalls.scm: Test it.
---
guix/build/syscalls.scm | 15 +++++++++++++++
tests/syscalls.scm | 24 ++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 827a79d..e319368 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -46,6 +46,7 @@
swapoff
processes
mkdtemp!
+ pivot-root
CLONE_NEWNS
CLONE_NEWUTS
@@ -326,6 +327,20 @@ reassociated with, or 0 if there is no such limitation."
(list fdes nstype (strerror err))
(list err)))))))
+(define pivot-root
+ (let* ((ptr (dynamic-func "pivot_root" (dynamic-link)))
+ (proc (pointer->procedure int ptr (list '* '*))))
+ (lambda (new-root put-old)
+ "Change the root file system to NEW-ROOT and move the current root file
+system to PUT-OLD."
+ (let ((ret (proc (string->pointer new-root)
+ (string->pointer put-old)))
+ (err (errno)))
+ (unless (zero? ret)
+ (throw 'system-error "pivot_root" "~S ~S: ~A"
+ (list new-root put-old (strerror err))
+ (list err)))))))
+
\f
;;;
;;; Packed structures.
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index 80d2788..e34d37d 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -18,6 +18,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (test-syscalls)
+ #:use-module (guix utils)
#:use-module (guix build syscalls)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
@@ -112,6 +113,29 @@
(equal? (readlink (user-namespace clone-pid))
(readlink (user-namespace fork-pid))))))))))
+(test-assert "pivot-root"
+ (match (pipe)
+ ((in . out)
+ (match (clone (logior CLONE_NEWUSER CLONE_NEWNS))
+ (0
+ (close in)
+ (call-with-temporary-directory
+ (lambda (root)
+ (let ((put-old (string-append root "/real-root")))
+ (mount "none" root "tmpfs")
+ (mkdir put-old)
+ (call-with-output-file (string-append root "/test")
+ (lambda (port)
+ (display "testing\n" port)))
+ (pivot-root root put-old)
+ ;; The test file should now be located inside the root directory.
+ (write (file-exists "/test") out)
+ (close out))))
+ (primitive-exit 0))
+ (pid
+ (close out)
+ (read in))))))
+
(test-assert "all-network-interfaces"
(match (all-network-interfaces)
(((? string? names) ..1)
--
2.4.3
next prev parent reply other threads:[~2015-07-06 13:17 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-06 13:16 [PATCH 01/15] build: syscalls: Add additional mount flags David Thompson
2015-07-06 13:16 ` [PATCH 02/15] build: syscalls: Add unmount flags David Thompson
2015-07-07 14:50 ` Ludovic Courtès
2015-07-07 22:44 ` Thompson, David
2015-07-06 13:16 ` [PATCH 03/15] build: syscalls: Add mkdtemp! David Thompson
2015-07-07 13:15 ` Ludovic Courtès
2015-07-07 22:52 ` Thompson, David
2015-07-06 13:16 ` [PATCH 04/15] utils: Add call-with-temporary-directory David Thompson
2015-07-07 13:15 ` Ludovic Courtès
2015-07-07 22:54 ` Thompson, David
2015-07-06 13:16 ` [PATCH 05/15] build: syscalls: Add clone syscall wrapper David Thompson
2015-07-07 13:23 ` Ludovic Courtès
2015-07-08 0:28 ` Thompson, David
2015-07-11 10:18 ` Ludovic Courtès
2015-07-06 13:16 ` [PATCH 06/15] build: syscalls: Add setns " David Thompson
2015-07-07 13:28 ` Ludovic Courtès
2015-07-08 0:57 ` Thompson, David
2015-07-06 13:16 ` David Thompson [this message]
2015-07-07 13:35 ` [PATCH 07/15] build: syscalls: Add pivot-root Ludovic Courtès
2015-07-08 1:18 ` Thompson, David
2015-07-08 12:47 ` Ludovic Courtès
2015-07-06 13:16 ` [PATCH 08/15] gnu: build: Add Linux container module David Thompson
2015-07-07 13:51 ` Ludovic Courtès
2015-07-08 12:38 ` Thompson, David
2015-07-08 21:57 ` Ludovic Courtès
2015-07-09 12:56 ` Thompson, David
2015-07-06 13:16 ` [PATCH 09/15] gnu: system: Move <file-system-mapping> into (gnu system file-systems) David Thompson
2015-07-07 13:51 ` Ludovic Courtès
2015-07-08 1:21 ` Thompson, David
2015-07-06 13:16 ` [PATCH 10/15] gnu: system: Move file-system->spec to " David Thompson
2015-07-07 13:51 ` Ludovic Courtès
2015-07-08 1:22 ` Thompson, David
2015-07-06 13:16 ` [PATCH 11/15] gnu: system: Add Linux container module David Thompson
2015-07-07 13:55 ` Ludovic Courtès
2015-07-09 13:00 ` Thompson, David
2015-07-10 17:57 ` Ludovic Courtès
2015-07-06 13:16 ` [PATCH 12/15] gnu: system: Add Linux container file systems David Thompson
2015-07-07 13:56 ` Ludovic Courtès
2015-07-09 12:56 ` Thompson, David
2015-07-06 13:16 ` [PATCH 13/15] scripts: system: Add 'container' action David Thompson
2015-07-07 14:05 ` Ludovic Courtès
2015-10-27 0:24 ` Thompson, David
2015-10-27 17:41 ` Ludovic Courtès
2015-10-30 17:28 ` Thompson, David
2015-07-06 13:16 ` [PATCH 14/15] scripts: environment: Add --container option David Thompson
2015-07-07 14:35 ` Ludovic Courtès
2015-07-09 13:16 ` Thompson, David
2015-07-10 18:03 ` Ludovic Courtès
2015-09-05 23:45 ` Thompson, David
2015-09-11 12:39 ` Ludovic Courtès
2015-10-10 21:11 ` Thompson, David
2015-10-11 19:34 ` Ludovic Courtès
2015-10-17 10:05 ` Ludovic Courtès
2015-10-22 1:23 ` Thompson, David
2015-10-25 21:38 ` Ludovic Courtès
2015-10-26 0:35 ` Thompson, David
2015-10-27 10:13 ` Ludovic Courtès
2015-10-31 1:25 ` Thompson, David
2015-10-31 10:28 ` Ludovic Courtès
2015-07-06 13:16 ` [PATCH 15/15] scripts: Add 'container' subcommand David Thompson
2015-07-07 14:50 ` Ludovic Courtès
2015-10-27 0:31 ` Thompson, David
2015-10-27 17:46 ` Ludovic Courtès
2015-07-07 13:14 ` [PATCH 01/15] build: syscalls: Add additional mount flags Ludovic Courtès
2015-07-07 22:42 ` Thompson, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436188604-2813-7-git-send-email-dthompson2@worcester.edu \
--to=dthompson2@worcester.edu \
--cc=davet@gnu.org \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).