aboutsummaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-09-18 20:19:56 +0200
committerLudovic Courtès <ludo@gnu.org>2014-09-18 20:19:56 +0200
commit715fc9d44d284a0c5e1ded45091eaf979aa5ecd4 (patch)
treeb13a651a1a624043348cc0d411aca5fbbe42c19a /guix/build
parent510f9d8624fb3440e0ec310826258d13e4f58c32 (diff)
downloadgnu-guix-715fc9d44d284a0c5e1ded45091eaf979aa5ecd4.tar
gnu-guix-715fc9d44d284a0c5e1ded45091eaf979aa5ecd4.tar.gz
syscalls: Add 'swapon' and 'swapoff'.
* guix/build/syscalls.scm (swapon, swapoff): New procedures. * tests/syscalls.scm ("swapon, ENOENT/EPERM", "swapoff, EINVAL/EPERM"): New tests.
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/syscalls.scm26
1 files changed, 26 insertions, 0 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index c8ec13983b..f910ebd152 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -31,6 +31,8 @@
MS_MOVE
mount
umount
+ swapon
+ swapoff
processes
IFF_UP
@@ -164,6 +166,30 @@ constants from <sys/mount.h>."
(when update-mtab?
(remove-from-mtab target))))))
+(define swapon
+ (let* ((ptr (dynamic-func "swapon" (dynamic-link)))
+ (proc (pointer->procedure int ptr (list '* int))))
+ (lambda* (device #:optional (flags 0))
+ "Use the block special device at DEVICE for swapping."
+ (let ((ret (proc (string->pointer device) flags))
+ (err (errno)))
+ (unless (zero? ret)
+ (throw 'system-error "swapon" "~S: ~A"
+ (list device (strerror err))
+ (list err)))))))
+
+(define swapoff
+ (let* ((ptr (dynamic-func "swapoff" (dynamic-link)))
+ (proc (pointer->procedure int ptr '(*))))
+ (lambda (device)
+ "Stop using block special device DEVICE for swapping."
+ (let ((ret (proc (string->pointer device)))
+ (err (errno)))
+ (unless (zero? ret)
+ (throw 'system-error "swapff" "~S: ~A"
+ (list device (strerror err))
+ (list err)))))))
+
(define (kernel? pid)
"Return #t if PID designates a \"kernel thread\" rather than a normal
user-land process."