Commit Graph

113 Commits

Author SHA1 Message Date
Ludovic Courtès 70dfdd501a
syscalls: Adjust 'clone' to Guile 2.2.
Before that, something like:

  (call-with-container
    (lambda ()
      (match (primitive-fork)
        …)))

would hang in 'primitive-fork' as the child process (the one started in
the container) would try to pthread_join the finalization thread in
'stop_finalization_thread' in libguile, not knowing that this thread is
nonexistent.

* guix/build/syscalls.scm (%set-automatic-finalization-enabled?!): New
procedure.
(without-automatic-finalization): New macro.
(clone): Wrap PROC call in 'without-automatic-finalization'.
2017-03-15 15:19:53 +01:00
Ludovic Courtès 334c95306a
syscalls: Adjust 'define-bits' to macro literal semantics of 2.2.
* guix/build/syscalls.scm (define-bits): Do not define NAMES... as
top-level variables since that prevents literal matches in 2.2.
Instead, determine constant values at expansion time.
2017-03-12 17:47:25 +01:00
Ludovic Courtès 3483f004a9
syscalls: Export 'read-utmpx'.
* guix/build/syscalls.scm (read-utmpx-from-port): New procedure.
* tests/syscalls.scm ("read-utmpx, EOF")
("read-utmpx"): New tests.
2017-01-24 00:46:37 +01:00
Ludovic Courtès 150309726f
syscalls: Add utmpx procedures and data structure.
* guix/build/syscalls.scm (<utmpx-entry>): New record type.
(%utmpx): New C struct.
(login-type): New bits.
(setutxent, endutxent, getutxent, utmpx-entries): New procedures.
2017-01-19 23:21:25 +01:00
Ludovic Courtès 57f068bec5
syscalls: Extract 'bytes->string'.
* guix/build/syscalls.scm (bytes->string): New procedure.
(bytevector->string-list): Use it.
2017-01-19 23:20:57 +01:00
Ludovic Courtès a6e0ae4046
syscalls: 'terminal-columns' swallows ENOSYS.
* guix/build/syscalls.scm (terminal-columns): Catch ENOSYS.
2017-01-01 23:38:07 +01:00
Ludovic Courtès 9e38e3cf52
syscalls: Add 'add-network-route/gateway' and 'delete-network-route'.
* guix/build/syscalls.scm (SIOCADDRT, SIOCDELRT): New variables.
(%rtentry): New C struct.
(RTF_UP, RTF_GATEWAY, %sockaddr-any): New variables.
(add-network-route/gateway, delete-network-route): New procedures.
* tests/syscalls.scm ("add-network-route/gateway")
("delete-network-route"): New tests.
2016-11-21 00:34:48 +01:00
Ludovic Courtès 8eb790f368
syscalls: Add 'c-struct-field-offset'.
* guix/build/syscalls.scm (define-c-struct-macro): New macro.
(define-c-struct): Use it.
(c-struct-field-offset): New macro.
2016-11-21 00:34:48 +01:00
Ludovic Courtès e9ff8d9ff1
syscalls: 'configure-network-interface' has a #:netmask parameter.
* guix/build/syscalls.scm (configure-network-interface): Add #:netmask
keyword parameter and honor it.
2016-11-17 23:21:47 +01:00
Ludovic Courtès 67e5f3b71d
syscalls: Add bindings for SIOCGIFNETMASK and SIOCSIFNETMASK.
* guix/build/syscalls.scm (SIOCGIFNETMASK, SIOCSIFNETMASK): New
variables.
(set-network-interface-netmask, network-interface-netmask): New
procedures.
* tests/syscalls.scm ("network-interface-netmask lo")
("set-network-interface-netmask"): New tests.
2016-11-16 23:38:06 +01:00
Ludovic Courtès 9d9d0c9c98
syscalls: Use 'define-c-struct' for 'struct ifconf'.
* guix/build/syscalls.scm (ifconf-struct): Remove.
(%ifconf-struct): New C struct.
(network-interface-names): Use 'make-bytevector' and 'write-ifconf!'
instead of 'make-c-struct', and 'read-ifconf' instead of
'parse-c-struct'.
2016-11-16 23:38:05 +01:00
Ludovic Courtès f43714e620
syscalls: C struct writer correctly handles pointer fields.
* guix/build/syscalls.scm (write-type): Add case for '*.
2016-11-16 23:38:05 +01:00
Ludovic Courtès 26ffb69399
syscalls: Use #:return-errno? when it is available.
* guix/build/syscalls.scm (errno): Do not export.
(syscall->procedure): Change to return a procedure that returns both the
value and errno.  Use #:return-errno? where available.
(mount, umount, swapon, swapoff, mkdtemp!, fdatasync, statfs)
(clone, setns, pivot-root, fcntl-flock, network-interface-names)
(network-interface-flags, set-network-interface-flags)
(set-network-interface-address, network-interface-address):
(network-interfaces, tcgetattr, tcsetattr, terminal-window-size): Adjust
accordingly using 'let-values'.
2016-09-06 11:12:11 +02:00
Ludovic Courtès 2ff0da0257
file-systems: Always use (guix build syscalls).
* gnu/build/file-systems.scm: Use (guix build syscalls)
unconditionally.  Override the 'mount' and 'umount' bindings
when (guile) provides them.
(MS_RDONLY, MS_NOSUID, MS_NODEV, MS_NOEXEC, MS_REMOUNT)
(MS_BIND, MS_MOVE): Remove.
* guix/build/syscalls.scm (%libc-errno-pointer): Add
'false-if-exception' around 'dynamic-func'.
2016-09-05 00:06:47 +02:00
Ludovic Courtès d1f33ba44b
syscalls: Use 'syscall->procedure' everywhere.
* guix/build/syscalls.scm (mkdtemp!, setns, %ioctl, network-interfaces):
(free-ifaddrs): Use 'syscall->procedure'.
2016-06-13 18:05:54 +02:00
Ludovic Courtès 1752a17a1e
utils: 'with-atomic-file-output' calls 'fdatasync'.
Suggested by Danny Milosavljevic <dannym@scratchpost.org>
at <https://lists.gnu.org/archive/html/guix-devel/2016-06/msg00456.html>.

* guix/build/syscalls.scm (fdatasync): New procedure.
* guix/utils.scm (with-atomic-file-output): Use it.  Use 'close-port'
instead of 'close'.
2016-06-13 18:05:54 +02:00
Ludovic Courtès d33c8b4649
syscalls: Use 'define-c-struct' for 'fcntl-flock'.
* guix/build/syscalls.scm (%struct-flock): Use 'define-c-struct'.
(fcntl-flock): Use 'write-flock!' and 'make-bytevector' instead of
'make-c-struct'.
2016-05-06 13:25:30 +02:00
Ludovic Courtès 4e0ea3eb28
utils: Move 'fcntl-flock' to (guix build syscalls).
* guix/utils.scm (%struct-flock, F_SETLKW, F_SETLK, F_xxLCK)
(fcntl-flock): Move to...
* guix/build/syscalls.scm: ... here.  New variables.
* guix/nar.scm: Adjust imports accordingly.
* tests/utils.scm ("fcntl-flock wait", "fcntl-flock non-blocking"): Move
to...
* tests/syscalls.scm: ... here.  New tests.
(temp-file): New variable.
2016-05-06 13:25:30 +02:00
Ludovic Courtès a8f3424b25
syscalls: Wrap TCSA* constants in 'tcsetattr-action' macro.
* guix/build/syscalls.scm (tcsetattr-action): New macro.
(TCSANOW, TCSADRAIN, TCSAFLUSH): Remove.
(tcsetattr): Adjust docstring accordingly.
* tests/syscalls.scm ("tcsetattr"): Adjust accordingly.
2016-05-03 17:45:29 +02:00
Ludovic Courtès ae4ff9f359
syscalls: Add 'tcgetattr' and 'tcsetattr' bindings.
* guix/build/syscalls.scm (bits->symbols-body, define-bits)
(local-flags): New macros.
(TCSANOW, TCSADRAIN, TCSAFLUSH): New variables.
(<termios>): New record type.
(%termios): New C structure.
(tcgetattr, tcsetattr): New procedures.
* tests/syscalls.scm ("tcgetattr ENOTTY", "tcgetattr")
("tcsetattr"): New tests.
2016-05-02 00:05:36 +02:00
Ludovic Courtès 00cd41974e
syscalls: Implement arrays in 'define-c-struct' and use it.
* guix/build/syscalls.scm (sizeof*, alignof*, write-type, read-type):
Add support for (array ...) forms.
* guix/build/syscalls.scm (<file-system>)[spare0, spare1]: Remove.
[spare]: New field.
* guix/build/syscalls.scm (%statfs)[identifier]: Change to (array int 2).
[spare0, spare1]: Remove.
[spare]: New field.
2016-05-02 00:05:36 +02:00
Ludovic Courtès 96f2a432bf
syscalls: 'statfs' explicitly binds 'statfs64'.
* guix/build/syscalls.scm (statfs): Explicitly bind "statfs64".
2016-04-30 23:40:42 +02:00
Ludovic Courtès 200dac0654
syscalls: statfs: Add missing 'mount-flags' field of 'struct statfs'.
* guix/build/syscalls.scm (<file-system>)[mount-flags]: New field.
[spare2]: Remove.
(%statfs): Likewise.
2016-04-30 23:40:42 +02:00
Ludovic Courtès 5cd25aad3c
syscalls: 'terminal-columns' catches EINVAL on the TIOCGWINSZ ioctl.
Reported by Mark H Weaver <mhw@netris.org>.

* guix/build/syscalls.scm (terminal-columns): Tolerate EINVAL.
* tests/syscalls.scm ("terminal-window-size ENOTTY"): Likewise.
2016-04-25 23:34:20 +02:00
Ludovic Courtès a1f708787d
syscalls: Add 'statfs'.
* guix/build/syscalls.scm (<file-system>): New record type.
(fsword): New macro.
(%statfs): New C struct.
(statfs): New procedure.
2016-04-25 23:27:09 +02:00
Ludovic Courtès 785cfa8791
syscalls: 'define-c-struct' computes the struct size.
* guix/build/syscalls.scm (struct-alignment, struct-size): New macros.
(define-c-struct): Add 'size' parameter and honor it.
(sockaddr-in, sockaddr-in6, ifaddrs, winsize): Adjust accordingly.
(%struct-ifaddrs-type, %sizeof-ifaddrs, winsize-struct): Remove.
(terminal-window-size): Use 'make-bytevector' instead of 'make-c-struct'.
2016-04-25 23:27:09 +02:00
Ludovic Courtès f77863a09e
syscalls: Second argument of packed-struct read is now optional.
* guix/build/syscalls.scm (define-c-struct)[read]: OFFSET defaults to 0.
(unfold-interface-list): Remove second argument to 'read-ifaddrs'.
(terminal-window-size): Remove second argument to 'read-winsize'.
2016-04-25 23:27:09 +02:00
Ludovic Courtès 73f38d5ff3
syscalls: Move code around [NFC].
* guix/build/syscalls.scm: Move packed structure handling to the top.
2016-04-25 23:27:09 +02:00
Mark H Weaver 4f8cede062 syscalls: If a syscall is not available, defer the error.
* guix/build/syscalls.scm (syscall->procedure): New procedure.
  (mount, umount, swapon, swapoff, clone, pivot-root): Use it.
  (clone): Add case for nonexistent syscall id.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-04-18 19:36:31 +02:00
Ludovic Courtès 6d2b43915f syscalls: 'terminal-columns' ignores non-file ports.
* guix/build/syscalls.scm (terminal-columns): Call
'terminal-window-size' only when PORT is a file port.
* tests/syscalls.scm ("terminal-columns non-file port"): New test.
2016-04-16 00:52:19 +02:00
Ludovic Courtès 29ff6d9fcc syscalls: Add TIOCGWINSZ bindings.
* guix/build/syscalls.scm (TIOCGWINSZ): New macro.
(<window-size>): New record type.
(winsize): New C struct.
(winsize-struct): New variable.
(terminal-window-size, terminal-columns): New procedures.
2016-04-15 00:32:18 +02:00
Ludovic Courtès 001dae0d74 syscalls: <interface> printer correctly handles lack of sockaddr.
Reported by Danny Milosavljevic <dannym@scratchpost.org>
in <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22612#16>.

* guix/build/syscalls.scm (write-interface): Check whether ADDRESS is
true.
2016-03-25 17:24:47 +01:00
Ludovic Courtès a220b262db syscalls: 'all-network-interface-names' accepts non-alphanumeric characters.
This fixes interfaces with a dash or other characters being ignored.
Suggested by Jookia <166291@gmail.com>.

* guix/build/syscalls.scm (%interface-line): Use [[:graph:]] instead
of [[:alnum:]].
2016-02-03 11:21:11 +01:00
Ludovic Courtès 0e3cc3116d syscalls: Fix ABI mismatch for 'clone'.
Fixes <http://bugs.gnu.org/21694>.

* guix/build/syscalls.scm (clone): Change 'syscall' parameter types to
  LONG, UNSIGNED-LONG, or '*; make sure it has 6 parameters.  Adjust
  caller accordingly.
2015-10-17 11:53:25 +02:00
David Thompson ee78d02452 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.
2015-09-07 13:09:58 -04:00
David Thompson cf897cbacc build: syscalls: Properly handle clone errors.
* guix/build/syscalls.scm (clone): Catch -1 return value and throw error.
2015-09-05 13:42:02 -04:00
David Thompson 39e336b5c8 syscalls: setns: Skip binding if there is no such C function.
On systems with a glibc prior to 2.14, the 'setns' function is not available.

Thanks to Eric Bavier for reporting the issue.

* guix/build/syscalls.scm (setns): Wrap with 'false-if-exception'.
2015-08-17 14:51:18 -04:00
Ludovic Courtès e7f5691d45 syscalls: Add 'network-interfaces', which wraps libc's 'getifaddrs'.
Based on discussions with Rohan Prinja <rohan.prinja@gmail.com>.

* guix/build/syscalls.scm (<interface>): New record type.
  (write-interface, values->interface, unfold-interface-list,
  network-interfaces, free-ifaddrs): New procedures.
  (ifaddrs): New C struct.
  (%struct-ifaddrs-type, %sizeof-ifaddrs): New macros.
* tests/syscalls.scm ("network-interfaces returns one or more interfaces",
  "network-interfaces returns \"lo\""): New tests.
2015-07-25 14:43:45 +02:00
Ludovic Courtès 573b4c1ff3 syscalls: 'define-c-struct' properly align reads.
* guix/build/syscalls.scm (alignof*, align): New macros.
  (write-types, read-types): Use 'align' to compute the actual offset to
  read/write a value of TYPE0.
2015-07-25 14:43:45 +02:00
Ludovic Courtès 3ca337699a syscalls: 'read-socket-address' gracefully handles unsupported families.
* guix/build/syscalls.scm (PF_PACKET, AF_PACKET): New variables.
  (read-socket-address): Make 'index' optional.  Return (vector FAMILY) when
  FAMILY is neither AF_INET nor AF_INET6.
2015-07-25 14:43:44 +02:00
Ludovic Courtès 4a30e84e61 syscalls: 'define-c-struct' distinguishes pointers from integers.
* guix/build/syscalls.scm (read-type): Add special-case for when TYPE is '*.
2015-07-25 14:43:44 +02:00
Ludovic Courtès b89e74054e syscalls: Rename 'network-interfaces' and 'all-network-interfaces'.
* guix/build/syscalls.scm (network-interfaces): Rename to...
  (network-interface-names): ... this.
  (all-network-interfaces): Rename to...
  (all-network-interface-names): ... this.
* gnu/services/networking.scm (dhcp-client-service): Adjust accordingly.
* tests/syscalls.scm ("all-network-interfaces"): Rename to...
  ("all-network-interface-names"): ... this, and adjust accordingly.
  ("network-interfaces"): Rename to...
  ("network-interface-names"): ... this, and adjust accordingly.
2015-07-25 14:43:44 +02:00
Ludovic Courtès 13f0c6ed41 syscalls: Struct deserializer can now return arbitrary objects.
* guix/build/syscalls.scm (read-types): Add RETURN and VALUES parameters.
  (define-c-struct): Add WRAP-FIELDS parameter and pass it to 'read-types'.
  (sockaddr-in, sockaddr-in6): Add first argument that uses
  'make-socket-address'.
  (read-socket-address): Remove 'match' on the result of 'read-sockaddr-in'
  and 'read-sockaddr-in6'.
2015-07-17 23:31:29 +02:00
David Thompson df3ce5c123 build: syscalls: Add pivot-root.
* guix/build/syscalls.scm (pivot-root): New procedure.
* tests/syscalls.scm ("pivot-root"): New test.
2015-07-07 21:16:25 -04:00
David Thompson 43ace6ea76 build: syscalls: Add setns.
* guix/build/syscalls.scm (setns): New procedure.
* tests/syscalls.scm ("setns"): New test.

squash: setns
2015-07-07 20:55:09 -04:00
David Thompson 8950ed11c6 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.
2015-07-07 20:35:08 -04:00
David Thompson b4abdeb63b build: syscalls: Add mkdtemp!
* guix/build/syscalls.scm (mkdtemp!): New procedure.
* tests/syscalls.scm ("mkdtemp!"): New test.
2015-07-07 18:46:44 -04:00
David Thompson b16d138a0a build: syscalls: Add unmount flags.
* guix/build/syscalls.scm (MNT_FORCE, MNT_DETACH, MNT_EXPIRE)
  (UMOUNT_NOFOLLOW): New variables.
2015-07-07 18:38:41 -04:00
David Thompson 577c02eb40 build: syscalls: Add additional mount flags.
* guix/build/syscalls.scm (MS_NOSUID, MS_NODEV, MS_NOEXEC, MS_STRICTATIME):
  New variables.
2015-07-07 18:38:41 -04:00
Ludovic Courtès 60a56db007 services: swap: Use 'restart-on-EINTR'.
* gnu/services/base.scm (swap-service)[start, stop]: Use 'restart-on-EINTR'.
* guix/build/syscalls.scm (swapoff): Fix typo in 'throw' arguments.
2015-05-22 11:51:12 +02:00
Ludovic Courtès ea98270443 syscalls: Add 'restart-on-EINTR'.
* guix/build/syscalls.scm (call-with-restart-on-EINTR): New procedure.
  (restart-on-EINTR): New macro.
2015-05-22 11:51:12 +02:00
Ludovic Courtès 6944fdbdbd syscalls: Add 'set-network-interface-up'.
* guix/build/syscalls.scm (set-network-interface-up): New procedure.
2015-05-17 23:20:59 +02:00
宋文武 9331ba5dd9 linux-boot: Make /etc/mtab a symlink to /proc/self/mounts.
Fixes <http://bugs.gnu.org/19491>.

* gnu/build/linux-boot.scm (mount-root-file-system): Make /root/etc/mtab
  a symlink to /proc/self/mounts.
* gnu/build/file-systems.scm (mount-file-system): Don't update /etc/mtab.
* guix/build/syscalls.scm (mount, umount): Have #:update-mtab? default to
  #f.
2015-01-05 22:24:00 +08:00
Ludovic Courtès c9bf64d6d7 syscalls: Add more procedures for network interfaces.
* guix/build/syscalls.scm (sizeof*, type-size, write-type, write-types,
  read-type, read-types, define-c-struct): New macros.
  (SIOCSIFFLAGS, SIOCGIFADDR, SIOCSIFADDR): New variables.
  (sockaddr-in, sockaddr-in6): New C structs.
  (write-socket-address!, read-socket-address,
  set-network-interface-flags, set-network-interface-address,
  network-interface-address, configure-network-interface): New
  procedures.
2014-12-19 17:15:53 +01:00
Ludovic Courtès cd4a3cb359 syscalls: Update /etc/mtab, not /etc/fstab.
* guix/build/syscalls.scm (remove-from-mtab): Replace "fstab" with
  "mtab".
2014-11-14 00:41:01 +01:00
Ludovic Courtès ccea821bef syscalls: Add 'mount-points'.
* guix/build/syscalls.scm (mount-points): New procedure.
* tests/syscalls.scm ("mount-points"): New test.
2014-11-10 22:42:14 +01:00
Ludovic Courtès 8591fae4cf syscalls: Adjust /proc/net/dev parser for old kernels.
* guix/build/syscalls.scm (%interface-line): Remove whitespace in rest
  pattern.  (There's no extra whitespace after the colon with Linux
  2.6.32.)
2014-09-22 21:12:26 +02:00
Ludovic Courtès 715fc9d44d syscalls: Add 'swapon' and 'swapoff'.
* guix/build/syscalls.scm (swapon, swapoff): New procedures.
* tests/syscalls.scm ("swapon, ENOENT/EPERM", "swapoff, EINVAL/EPERM"):
  New tests.
2014-09-18 20:19:56 +02:00
Ludovic Courtès 4d54785c69 syscalls: Add 'all-network-interfaces'.
* guix/build/syscalls.scm (network-interfaces): Update docstring.
  (%interface-line): New variable.
  (all-network-interfaces): New procedure.
* tests/syscalls.scm ("all-network-interfaces"): New test.
  ("network-interfaces"): Change to make sure the result is a subset
  of (all-network-interfaces).
2014-09-14 23:49:02 +02:00
Ludovic Courtès 973eea3478 syscalls: Add 'network-interface-flags'.
* guix/build/syscalls.scm (SIOCGIFFLAGS, IFF_UP, IFF_BROADCAST,
  IFF_LOOPBACK, IF_NAMESIZE): New variables.
  (network-interface-flags, loopback-network-interface?): New
  procedures.
* tests/syscalls.scm ("network-interface-flags",
  "loopback-network-interface?"): New tests.
2014-09-14 23:49:02 +02:00
Ludovic Courtès 7585016f53 syscalls: Add 'network-interfaces'.
* guix/build/syscalls.scm (SIOCGIFCONF, ifconf-struct,
  ifreq-struct-size): New variables.
  (%ioctl, bytevector->string-list, network-interfaces): New
  procedures.
* tests/syscalls.scm ("network-interfaces"): New test.
2014-09-14 23:49:02 +02:00
Ludovic Courtès 17a4d34489 syscalls: Add 'processes' to list all the live processes.
* guix/build/syscalls.scm (kernel?, processes): New procedures.
2014-05-14 19:07:03 +02:00
Ludovic Courtès 29fa45f45d Add (guix build syscalls).
* guix/build/syscalls.scm, tests/syscalls.scm: New files.
* Makefile.am (MODULES): Add guix/build/syscalls.scm.
  (SCM_TESTS): Add tests/syscalls.scm.
* guix/utils.scm (%libc-errno-pointer, errno): Remove; take from (guix
  build syscalls).
2014-05-10 22:55:34 +02:00