Commit Graph

137 Commits

Author SHA1 Message Date
MarcoFalke d5ca4d4fd7
syscalls: Define riscv64 syscall ID for clone.
* guix/build/syscalls.scm (clone): Add an entry for riscv64.

This allows the use of --container on riscv64.

Change-Id: I12b3cb5e2aa248266d006b6e456082f4ddc70e62
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-12-13 12:58:43 +01:00
Ludovic Courtès a14dafaa01
syscalls: Add fallback case for ‘terminal-string-width’.
This makes ‘terminal-string-width’ synonymous with ‘string-length’ when
running one a statically-linked Guile, as is the case in some unit
tests, instead of throwing ENOSYS.

* guix/build/syscalls.scm (terminal-string-width): Use ‘dynamic-func’
and ‘pointer->procedure’ instead of ‘syscall->procedure’.  Return
‘string-length’ when one of the ‘dynamic-func’ calls fails.

Change-Id: Icf55c9e7c34b46fac91b665fb4a2ecb02160f22e
2023-11-25 16:29:25 +01:00
Julien Lepiller fd11d7fbf8
guix: syscalls: Add terminal-string-width.
* guix/build/syscalls.scm (terminal-width): New procedure.
* tests/syscalls.scm: Add tests.

Change-Id: I6c2caa9fbaffb1e8f4b8933103399be970d5a8f3
2023-11-11 11:07:27 +01:00
Sören Tempel dae956e796
syscalls: Consistently use existing linux? definition.
Instead of duplicating this existing logic across the source file. This
will make it easier to add additional linux targets (e.g. linux-musl) in
the future.

* guix/build/syscalls.scm (readdir*, write-socket-address!)
(read-socket-address): Use linux? constant.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Change-Id: I833c1d1630dcb8319584de1ea918cb22696f0058
2023-10-23 11:58:16 +02:00
Sören Tempel 54e6788267
syscalls: Add support for musl libc.
This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Usage of musl libc is detected via a new
musl-libc? variable using the Guile %host-type.

Using the new musl-libc? variable, we can now implement musl-specific
quirks. The two compatibility problems I encountered in this regard are
that musl dose not export a readdir64 and statfs64 symbol. On musl,
these two functions are implemented as CPP macros that expand to
readdir/statfs. To workaround that, a case-distinction was added.

The existing linux? variable has been modified to return true if the
%host-system contains "linux-" in order to ensure it is true for both
linux-gnu as well as linux-musl host systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (musl-libc?): New variable.
(linux?): Truth value on any linux system.
(statfs, readdir-procedure): Support musl libc.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Change-Id: Icc4101a062381240f977f4550344bde696513c52
2023-10-23 11:56:54 +02:00
Ludovic Courtès 836297eae5
syscalls: 'getxattr' throws upon error.
* guix/build/syscalls.scm (getxattr): Throw in the negative SIZE case.
2023-03-27 18:48:52 +02:00
Ludovic Courtès a68229b9a0
syscalls: 'with-file-lock' removes lock file upon exit.
Fixes <https://issues.guix.gnu.org/57501>.
Reported by Ricardo Wurmus <rekado@elephly.net>.

* guix/build/syscalls.scm (call-with-file-lock)
(call-with-file-lock/no-wait): Add call to 'delete-file' in unwind
handler.
2023-02-12 01:48:53 +01:00
Ludovic Courtès 047425a662
syscalls: Adjust for lack of 'libutil.so' on glibc >= 2.34.
This is a re-implementation of 3c8b6fd94c
done in a way that works for both glibc >= 2.34 and earlier versions.

* guix/build/syscalls.scm (syscall->procedure): When LIBRARY is true,
fall back to global symbols if (dynamic-link library) fails.

(cherry picked from commit 3f6c32a88f)
2022-12-02 14:58:26 +01:00
Ricardo Wurmus c585b4bc68
file-systems: Always do recursive bind mounts.
Fixes <https://issues.guix.gnu.org/59185>.

* guix/build/syscalls.scm (MS_REC): New variable.
* gnu/build/file-systems.scm (mount-flags->bit-mask): Set MS_REC bit when
bind-mounting.
2022-11-20 21:27:10 +01:00
Ludovic Courtès 6352e3a17b
syscalls: Define 'MS_NODIRATIME' and recognize "nodiratime".
Fixes <https://issues.guix.gnu.org/58663>.

This is a followup to b665dd4a99 and
dcb640f02b, allowing "nodiratime" to be
preserved for bind mounts.

* guix/build/syscalls.scm (MS_NODIRATIME): New variable.
(option-string->mount-flags): Recognize it.
(statfs-flags->mount-flags): Likewise.
2022-10-20 23:07:37 +02:00
Ludovic Courtès 8f53630f2f
syscalls: Avoid repeated calls to 'syscall->procedure'.
Commit 7df4d3465d and others changed
'mount', 'umount', & co. so they would call 'syscall->procedure' at each
call.  This change reverts to the previous behavior, where
'syscall->procedure' is called once.

* guix/build/syscalls.scm (mount, umount, reboot, load-linux-module):
Call 'syscall->procedure' only once.
2022-09-08 16:22:21 +02:00
Oleg Pykhalov 4b49487838
gnu: system: file-systems: Add shared flag.
* gnu/build/file-systems.scm (mount-flags->bit-mask, mount-file-system):
Handle shared flag.
* gnu/system/file-systems.scm (invalid-file-system-flags): Add shared to known
flags.
* guix/build/syscalls.scm (MS_SHARED): New variable.
* doc/guix.texi (File Systems): Document shared flag.
2022-08-10 07:12:25 +03:00
Ryan Sundberg bfdeba11f8
linux-container: Handle CLONE_NEWCGROUP and use it by default.
Adds low-level support for launching Linux containers with cgroup namespaces.

* gnu/build/linux-container.scm (%namespaces): Add 'cgroup.
(namespaces->bit-mask): Handle it.
* guix/build/syscalls.scm (CLONE_NEWCGROUP): New variable.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2022-01-05 23:44:18 +01:00
Ludovic Courtès b15e543d30
Merge branch 'master' into core-updates-frozen 2021-11-23 11:29:38 +01:00
Josselin Poiret 0831dfab75
system: Add swap flags.
* gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add
them.
* guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK,
SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them.
* gnu/build/file-systems.scm (swap-space->flags-bit-mask): Add it.
* gnu/services/base.scm (swap-service-type): Use it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-11-23 10:24:27 +01:00
Maxim Cournoyer 8444b44a8c
build: syscalls: Add a SET-CHILD-SUBREAPER! procedure.
* guix/build/syscalls.scm (PR_SET_CHILD_SUBREAPER): New variable.
(set-child-subreaper!): New procedure.
2021-11-20 08:57:00 -05:00
Ludovic Courtès 0a42998a50
syscalls: Gracefully handle failure to load libc's libutil.
In particular, libutil is not found when running code on a
statically-linked Guile.

Reported by mahmooz on #guix.

* guix/build/syscalls.scm (syscall->procedure): Add #:library parameter
and honor it.
(openpty, login-tty): Use 'syscall->procedure' instead of calling
'dynamic-link' directly.
2021-10-26 14:53:43 +02:00
Ludovic Courtès f87371bf3e
syscalls: Add 'openpty' and 'login-tty'.
* guix/build/syscalls.scm (openpty, login-pty): New procedures.
* tests/syscalls.scm ("openpty", "openpty + login-tty"): New tests.
2021-10-26 12:46:27 +02:00
Tobias Geerinckx-Rice 348f0c61ef
syscalls: Deduplicate device number conversion.
* guix/cpio.scm (device-number, device->major+minor):
Move to, and subsequently import from, …
* guix/build/syscalls.scm (device-number, device-number->major+minor):
…here.  Note the slight name change.
(mounts): Replace 16-bit open code with a DEVICE-NUMBER call.
* gnu/build/linux-boot.scm (device-number):
Remove duplicate 16-bit implementation in favour of the one above.
(resume-if-hibernated): Reuse DEVICE-NUMBER->MAJOR+MINOR.
2021-09-23 18:17:16 +02:00
Tobias Geerinckx-Rice 0dd136bc36
Revert "syscalls: 'terminal-dimension' ignores EPERM."
This reverts commit 17a102332a.
See <https://github.com/koverstreet/bcachefs/pull/277>.
2021-07-07 13:56:16 +02:00
Chris Marusich c29bfbfc78
syscalls: Fix RNDADDTOENTCNT on powerpc64le-linux.
This fixes the failing test add-to-entropy-count in tests/syscalls.scm on
powerpc64le-linux.

* guix/build/syscalls.scm (RNDADDTOENTCNT): When %host-type starts with
"powerpc64le", set this to #x80045201.  Otherwise, set it to #x40045201 as
before.
2021-03-23 23:19:58 -07:00
Chris Marusich b57de27d03
syscalls: Fix clone on powerpc64le-linux.
This makes the clone procedure work correctly and fixes some test failures on
powerpc64le-linux, including tests/containers.scm.

* guix/build/syscalls.scm (clone): Add an entry for ppc64le.
2021-03-23 23:19:57 -07:00
Chris Marusich 341dfe7eda
syscalls: mounts: Fix a matching bug.
On some systems, the columns in /proc/self/mountinfo look like this:

23 28 0:21 / /proc rw,nosuid,nodev,noexec,relatime shared:11 - proc proc rw

Before this change, the mounts procedure was written with the assumption that
the type and source could always be found in columns 8 and 9, respectively.
However, the proc(5) man page explains that there can be zero or more optional
fields starting at column 7 (e.g., "shared:11" above), so this assumption is
false in some situations.

* guix/build/syscalls.scm (mounts): Update the match pattern to use ellipsis
to match zero or more optional fields followed by a single hyphen.  Remove the
trailing ellipsis, since multiple ellipses are not allowed in the same level.
The proc(5) man page indicates that there are no additional columns, so it is
probably OK to match an exact number of columns at the end like this.
2021-03-15 21:22:43 -07:00
Ludovic Courtès 9a6ea2f8dc
syscalls: Define the ST_* constants and add 'statfs-flags->mount-flags'.
* guix/build/syscalls.scm (linux?): New variable.
(define-statfs-flags): New macro.
(ST_RDONLY, ST_NOSUID, ST_NODEV, ST_NOEXEC, ST_SYNCHRONOUS)
(ST_MANDLOCK, ST_WRITE, ST_APPEND, ST_IMMUTABLE, ST_NOATIME)
(ST_NODIRATIME, ST_RELATIME): New variables.
(statfs-flags->mount-flags): New procedure.
2021-03-10 23:21:33 +01:00
Ludovic Courtès 7e9d9f28e9
syscalls: Add 'mounts' and the <mount> record type.
* guix/build/syscalls.scm (<mount>): New record type.
(option-string->mount-flags, mount-flags)
(octal-decode, mounts): New procedures.
(mount-points): Rewrite in terms of 'mount'.
* tests/syscalls.scm ("mounts"): New test.
2021-02-25 11:29:35 +01:00
Ludovic Courtès 46bb1a41ae
syscalls: Define MS_RELATIME.
* guix/build/syscalls.scm (MS_RELATIME): New variable.
2021-02-25 11:29:35 +01:00
Jan (janneke) Nieuwenhuizen ab9e30039d
syscalls: set-thread-name, thread-name: Fix thinko.
* guix/build/syscalls.scm (set-thread-name, thread-name): Oops, fix thinko.
2020-06-08 16:49:03 +02:00
Jan (janneke) Nieuwenhuizen 1428926f1f
syscalls: set-thread-name, thread-name: Stub for the Hurd.
Avoid crash

    Backtrace:
    guix/build/syscalls.scm:405:8: In procedure prctl: Function not implemented

because of missing prctl on the Hurd.

* guix/build/syscalls.scm (set-thread-name, thread-name): Rename to ...
(set-thread-name!/linux,thread-name/linux): ...this.
(set-thread-name, thread-name): Swtich between linux implementation and or
stub.
2020-06-08 13:51:17 +02:00
Ludovic Courtès 17a102332a
syscalls: 'terminal-dimension' ignores EPERM.
Fixes <https://bugs.gnu.org/41581>.
Reported by Tobias Geerinckx-Rice <me@tobias.gr>.

* guix/build/syscalls.scm (terminal-dimension): Add EPERM to the list of
errno code for FALL-BACK.
2020-05-29 18:31:38 +02:00
Jesse Dowell b56cbe8974
syscalls: Properly match %HOST-TYPE.
Fixes <https://bugs.gnu.org/41546>.

Regression introduced in 0d371c633f.

* guix/build/syscalls.scm (write-socket-address!)
(read-socket-address): Use 'string-contains' instead of
'string-suffix?'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2020-05-29 18:31:38 +02:00
Jan (janneke) Nieuwenhuizen 0d371c633f
syscalls: Adjust 'sockaddr-in', 'sockaddr-in6' structs for the Hurd.
* guix/build/syscalls.scm (sockaddr-in,sockaddr-in6): Rename to ...
(sockaddr-in/linux, sockaddr-in6/linux): ... this.  Rename introduced bindings
as well.
(write-socket-address!/linux,read-socket-address/linux): Rename from
(write-socket-address!, read-socket-address): ... new switches between those
and ...
(write-socket-address!/hurd, read-socket-address/hurd): ... these new function.
2020-05-15 10:08:56 +02:00
Jan (janneke) Nieuwenhuizen df05842332
syscalls: Add 'getxattr'.
* guix/build/syscalls.scm (getxattr): New procedure.
* tests/syscalls.scm ("getxattr, setxattr"): Test it, together with setxattr.
2020-05-14 00:48:12 +02:00
Jan (janneke) Nieuwenhuizen d155c9d934
syscalls: Add 'setxattr'.
* guix/build/syscalls.scm (setxattr): New procedure.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2020-05-13 23:26:06 +02:00
Jan (janneke) Nieuwenhuizen 598be42dfa
syscalls: Add ioctl flags for the Hurd.
Use

    #include <stdio.h>
    #include <net/if.h>
    #include <hurd/ioctl.h>

    int
    main ()
    {
      printf ("SIOCSIFFLAGS #x%x\n", SIOCSIFFLAGS);
      printf ("SIOCGIFADDR #x%x\n", SIOCGIFADDR);
      printf ("SIOCSIFADDR #x%x\n", SIOCSIFADDR);
      printf ("SIOCGIFNETMASK #x%x\n", SIOCGIFNETMASK);
      printf ("SIOCSIFNETMASK #x%x\n", SIOCSIFNETMASK);
    #if 0
      printf ("SIOCADDRT #x%x\n", SIOCADDRT);
      printf ("SIOCDELRT #x%x\n", SIOCDELRT);
    #endif
    }

to fill in some blanks.  Adding and removing route apparently not supported.

* guix/build/syscalls.scm (SIOCSIFFLAGS SIOCGIFADDR, SIOCSIFADDR,
SIOCGIFNETMASK, SIOCSIFNETMASK):
2020-05-07 07:11:03 +02:00
Ludovic Courtès 86f5decd20
syscalls: 'define-c-struct' supports cross-compilation.
Reported by Jan (janneke) Nieuwenhuizen <janneke@gnu.org>.

Before that, we'd always use the 'sizeof' and 'alignof' value obtained
from the host at macro-expansion time.

* guix/build/syscalls.scm (sizeof*, alignof*): When the target word size
differs from the host word size, emit a call to 'sizeof'/'alignof'.
2020-05-05 23:45:56 +02:00
Julien Lepiller fd546bbbee
syscalls: Fix Linux detection in 'readdir*'.
* guix/build/syscalls.scm (readdir*): Fix Linux detection for
`arm-unknown-linux-gnueabihf'.
2020-04-20 16:30:14 +02:00
Ludovic Courtès 82d8959e5d
syscalls: 'readdir*' chooses between the Linux and Hurd code at run time.
Partly fixes <https://bugs.gnu.org/40574>.
Reported by Jan Nieuwenhuizen <janneke@gnu.org>.

Previously, we'd choose at expansion time whether to use the Hurd or the
Linux variant, taking the cross-compilation target into account.  This
would lead to the wrong decision when (guix build syscalls) is evaluated
while we're cross-compiling to GNU/Hurd.

This is a followup to 1ab9e48339.

* guix/build/syscalls.scm (define-generic-identifier)
(read-dirent-header, %struct-dirent-header, sizeof-dirent-header):
Remove.
(readdir*): Rename to...
(readdir-procedure): ... this, and add parameters.
(readdir*): Define as a call to 'readdir-procedure' as a function of
%HOST-TYPE.
2020-04-16 18:33:21 +02:00
Ludovic Courtès 9a067fe7ee
syscalls: 'with-file-lock' re-grabs lock when reentering its dynamic extent.
* guix/build/syscalls.scm (call-with-file-lock)
(call-with-file-lock/no-wait): Initialize PORT in the 'dynamic-wind'
"in" handler.  This allows us to re-enter a captured continuation and
have the lock grabbed anew.
2020-03-22 12:42:51 +01:00
Ludovic Courtès b782688d71
syscalls: Pass the right 'throw' arguments in 'call-with-file-lock/no-wait'.
Reported by Matt Wette <matt.wette@gmail.com>
in <https://bugs.gnu.org/39194>.

* guix/build/syscalls.scm (call-with-file-lock/no-wait): When
re-throwing, pass KEY in addition to ARGS.
2020-01-19 23:11:37 +01:00
Guillaume Le Vaillant 0dc5c85638
file-systems: Add support for 'strict-atime' and 'lazy-time' flags.
* guix/build/syscalls.scm (MS_LAZYTIME): New variable.
* gnu/build/file-systems.scm (mount-flags->bit-mask): Add match rules for
  'strict-atime' and 'lazy-time'.
* doc/guix.texi (File Systems): Add 'strict-atime' and 'lazy-time' to the list
  of supported flags.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2019-12-07 01:00:24 +01:00
Ludovic Courtès 3f8e890d91
ui: 'with-profile-lock' keeps going upon ENOLCK.
* guix/build/syscalls.scm (call-with-file-lock/no-wait): Really pass
ARGS to HANDLER.  Return #f when HANDLER is called.
* guix/ui.scm (profile-lock-handler): Emit a mere warning upon ENOLCK.
2019-11-29 15:54:20 +01:00
Julien Lepiller f49e913188
guix: Add file-locking with no wait.
* guix/build/syscalls.scm (with-file-lock/no-wait): New procedure.
(lock-file): Take a #:wait? key.
2019-11-08 21:52:30 +01:00
Ludovic Courtès 5e5f716794
syscalls: Add 'add-to-entropy-count'.
* guix/build/syscalls.scm (RNDADDTOENTCNT): New variable.
(add-to-entropy-count): New procedure.
* tests/syscalls.scm ("add-to-entropy-count"): New test.
2019-10-05 22:05:02 +02:00
Ludovic Courtès 96783ed627
syscalls: 'define-as-needed' does not re-export local variables.
Fixes <https://bugs.gnu.org/36723>.
Reported by Timothy Sample <samplet@ngyro.com>.

* guix/build/syscalls.scm (define-as-needed): Rewrite to use lower-level
module primitives; define VARIABLE only if it's not already defined to
avoid "re-exporting local variable" error.
2019-07-19 00:52:36 +02:00
Ludovic Courtès 456c7ade09
syscalls: Use 'define-as-needed' for 'AT_' constants introduced in Guile 2.2.5.
* guix/build/syscalls.scm (AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_REMOVEDIR)
(AT_SYMLINK_FOLLOW, AT_NO_AUTOMOUNT, AT_EMPTY_PATH): Define using
'define-as-needed'.
2019-07-15 10:00:12 +02:00
Ludovic Courtès 4593f5a654
syscalls: Add 'terminal-rows'.
* guix/build/syscalls.scm (terminal-dimension): New procedure.
(terminal-columns): Rewrite in terms of 'terminal-dimension'.
(terminal-rows): New procedure.
* tests/syscalls.scm ("terminal-rows"): New test.
2019-06-27 11:14:40 +02:00
Ludovic Courtès 5f0cf1df71
syscalls: 'with-lock-file' catches ENOSYS.
* guix/build/syscalls.scm (call-with-file-lock): Catch ENOSYS raised by
'lock-file'.
2019-06-05 23:10:36 +02:00
Ludovic Courtès 89ceb86ad4
syscalls: 'with-file-lock' expands to a call to 'call-with-file-lock'.
* guix/build/syscalls.scm (call-with-file-lock): New procedure.
(with-file-lock): Expand to a call to 'call-with-file-lock'.
2019-06-05 23:10:36 +02:00
Ludovic Courtès b7178c22bf
syscalls: Add 'with-file-lock' macro.
* guix/scripts/offload.scm (lock-file, unlock-file, with-file-lock):
Move to...
* guix/build/syscalls.scm: ... here.
2019-06-05 23:10:36 +02:00
Marius Bakke 5f5499d684
syscalls: Add 'arp-network-interface?'.
* guix/build/syscalls.scm (IFF_NOARP): New variable.
(arp-network-interface?): New public procedure.
2019-05-09 20:00:21 +02:00