summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-01-24 00:35:16 +0100
committerLudovic Courtès <ludo@gnu.org>2017-01-24 00:46:37 +0100
commit3483f004a98f103acff96effe1309cc620372e79 (patch)
treed88f597f5112645fdc4c4e578c1ae5eeae33e1cb
parent9475fd9217af370839cbfdb06b0a0a9a063d3469 (diff)
syscalls: Export 'read-utmpx'.
* guix/build/syscalls.scm (read-utmpx-from-port): New procedure. * tests/syscalls.scm ("read-utmpx, EOF") ("read-utmpx"): New tests.
-rw-r--r--guix/build/syscalls.scm13
-rw-r--r--tests/syscalls.scm9
2 files changed, 21 insertions, 1 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 475fc96490b..b68c48a05a0 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -21,6 +21,7 @@
21(define-module (guix build syscalls) 21(define-module (guix build syscalls)
22 #:use-module (system foreign) 22 #:use-module (system foreign)
23 #:use-module (rnrs bytevectors) 23 #:use-module (rnrs bytevectors)
24 #:autoload (ice-9 binary-ports) (get-bytevector-n)
24 #:use-module (srfi srfi-1) 25 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-9) 26 #:use-module (srfi srfi-9)
26 #:use-module (srfi srfi-9 gnu) 27 #:use-module (srfi srfi-9 gnu)
@@ -142,7 +143,8 @@
142 utmpx-time 143 utmpx-time
143 utmpx-address 144 utmpx-address
144 login-type 145 login-type
145 utmpx-entries)) 146 utmpx-entries
147 (read-utmpx-from-port . read-utmpx)))
146 148
147;;; Commentary: 149;;; Commentary:
148;;; 150;;;
@@ -1598,4 +1600,13 @@ always a positive integer."
1598 ((? utmpx? entry) 1600 ((? utmpx? entry)
1599 (loop (cons entry entries)))))) 1601 (loop (cons entry entries))))))
1600 1602
1603(define (read-utmpx-from-port port)
1604 "Read a utmpx entry from PORT. Return either the EOF object or a utmpx
1605entry."
1606 (match (get-bytevector-n port sizeof-utmpx)
1607 ((? eof-object? eof)
1608 eof)
1609 ((? bytevector? bv)
1610 (read-utmpx bv))))
1611
1601;;; syscalls.scm ends here 1612;;; syscalls.scm ends here
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index fb2c8e71004..92e02f33037 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -452,6 +452,15 @@
452 #t))) 452 #t)))
453 entries)))) 453 entries))))
454 454
455(test-assert "read-utmpx, EOF"
456 (eof-object? (read-utmpx (%make-void-port "r"))))
457
458(unless (access? "/var/run/utmpx" O_RDONLY)
459 (tes-skip 1))
460(test-assert "read-utmpx"
461 (let ((result (call-with-input-file "/var/run/utmpx" read-utmpx)))
462 (or (utmpx? result) (eof-object? result))))
463
455(test-end) 464(test-end)
456 465
457(false-if-exception (delete-file temp-file)) 466(false-if-exception (delete-file temp-file))