;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016-2020, 2022-2023 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2017 Tobias Geerinckx-Rice ;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests) #:use-module (guix gexp) #:use-module (guix diagnostics) #:use-module (guix records) #:use-module ((guix ui) #:select (warn-about-load-error)) #:use-module (gnu bootloader) #:use-module (gnu bootloader grub) #:use-module (gnu system) #:use-module (gnu system file-systems) #:use-module (gnu system shadow) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu services shepherd) #:use-module (guix discovery) #:use-module (guix monads) #:use-module ((guix store) #:select (%store-monad)) #:use-module ((guix utils) #:select (%current-system %current-target-system)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9 gnu) #:use-module (ice-9 match) #:export (marionette-configuration marionette-configuration? marionette-configuration-device marionette-configuration-imported-modules marionette-configuration-requirements marionette-servFrom 5e546a30789e5c9b3c94674b94cb63e16ee2e951 Mon Sep 17 00:00:00 2001 From: Philip McGrath <philip@philipmcgrath.com> Date: Thu, 4 Mar 2021 04:11:50 -0500 Subject: [PATCH] rktio: patch rktio_process for "/bin/sh" on Guix Racket provides the functions `system` and `process`, which execute shell commands using `sh` (or `cmd` on Windows). Racket assumes that `sh` can be found at "/bin/sh", which is not necessarily true on Guix. This patch adds a special case for "/bin/sh" to `rktio_process`, the C function that implements the core of `system`, `process`, and related Racket functions. If: 1. The nonstandard but ubiquitous macro `_PATH_BSHELL` from <paths.h> is defined; and 2. `rktio_process` is called with the exact path "/bin/sh"; and 3. The file specified by `_PATH_BSHELL` exists; then `rktio_process` will execute the file specified by `_PATH_BSHELL` instead of "/bin/sh". Checking that the path specified by `_PATH_BSHELL` exists safeguards against obscure errors if attempting to use stand-alone executables built by the patched Racket in non-Guix envoronments. --- Notes: See also chez-scheme-bin-sh.patch, racket-chez-scheme-bin-sh.patch, and zuo-bin-sh.patch. racket/src/rktio/rktio_process.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/racket/src/rktio/rktio_process.c b/racket/src/rktio/rktio_process.c index 862850d93a..87daafef76 100644 --- a/racket/src/rktio/rktio_process.c +++ b/racket/src/rktio/rktio_process.c @@ -9,6 +9,7 @@ # include <sys/wait.h> # include <errno.h> # include <unistd.h> +# include <paths.h> /* PATCHED for Guix */ # ifdef USE_ULIMIT # include <ulimit.h> # endif @@ -1358,12 +1359,14 @@ int rktio_process_allowed_flags(rktio_t *rktio) /*========================================================================*/ rktio_process_result_t *rktio_process(rktio_t *rktio, - const char *command, int argc, rktio_const_string_t *argv, + /* PATCHED for Guix (next line) */ + const char *_guix_orig_command, int argc, rktio_const_string_t *argv, rktio_fd_t *stdout_fd, rktio_fd_t *stdin_fd, rktio_fd_t *stderr_fd, rktio_process_t *group_proc, const char *current_directory, rktio_envvars_t *envvars, int flags) { + const char *command; /* PATCHED for Guix */ rktio_process_result_t *result; intptr_t to_subprocess[2], from_subprocess[2], err_subprocess[2]; int pid; @@ -1390,6 +1393,18 @@ rktio_process_result_t *rktio_process(rktio_t *rktio, int i; #endif +/* BEGIN PATCH for Guix */ +#if defined(_PATH_BSHELL) + command = + ((0 == strcmp(_guix_orig_command, "/bin/sh")) + && rktio_file_exists(rktio, _PATH_BSHELL)) + ? _PATH_BSHELL + : _guix_orig_command; +#else + command = _guix_orig_command; +#endif +/* END PATCH for Guix */ + /* avoid compiler warnings: */ to_subprocess[0] = -1; to_subprocess[1] = -1; base-commit: 78fef00d4d16a79fdf6ab31924b3a80cadf4b368 -- 2.41.0 ) (program-file "marionette-repl.scm" code)) (define (marionette-shepherd-service config) "Return the Shepherd service for the marionette REPL" (match config (($ device imported-modules extensions requirement) (list (shepherd-service (provision '(marionette)) ;; Always depend on UDEV so that DEVICE is available. (requirement `(udev ,@requirement)) (modules '((ice-9 match) (srfi srfi-9 gnu))) (start #~(make-forkexec-constructor (list #$(marionette-program device imported-modules extensions)))) (stop #~(make-kill-destructor))))))) (define marionette-service-type ;; This is the type of the "marionette" service, allowing a guest system to ;; be manipulated from the host. This marionette REPL is essentially a ;; universal backdoor. (service-type (name 'marionette-repl) (extensions (list (service-extension shepherd-root-service-type marionette-shepherd-service))) (description "The @dfn{marionette} service allows a guest system (virtual machine) to be manipulated by the host. It is used for system tests."))) (define* (marionette-operating-system os #:key (imported-modules '()) (extensions '()) (requirements '())) "Return a marionetteed variant of OS such that OS can be used as a marionette in a virtual machine--i.e., controlled from the host system. The marionette service in the guest is started after the Shepherd services listed in REQUIREMENTS. The packages in the list EXTENSIONS are made available from the backdoor REPL." (operating-system (inherit os) ;; Make sure the guest dies on error. (kernel-arguments (cons "panic=1" (operating-system-user-kernel-arguments os))) ;; Make sure the guest doesn't hang in the REPL on error. (initrd (lambda (fs . rest) (apply (operating-system-initrd os) fs #:on-error 'backtrace rest))) (services (cons (service marionette-service-type (marionette-configuration (requirements requirements) (extensions extensions) (imported-modules imported-modules))) (operating-system-user-services os))))) (define-syntax define-os-with-source (syntax-rules (use-modules operating-system) "Define two variables: OS containing the given operating system, and SOURCE containing the source to define OS as an sexp. This is convenient when we need both the object so we can instantiate it, and the source to create it so we can store in in a file in the system under test." ((_ (os source) (use-modules modules ...) (operating-system fields ...)) (begin (define os (operating-system fields ...)) (define source '(begin (use-modules modules ...) (operating-system fields ...))))))) ;;; ;;; Simple operating systems. ;;; (define %simple-os (operating-system (host-name "komputilo") (timezone "Europe/Berlin") (locale "en_US.UTF-8") (bootloader (bootloader-configuration (bootloader grub-bootloader) (targets '("/dev/sdX")))) (file-systems (cons (file-system (device (file-system-label "my-root")) (mount-point "/") (type "ext4")) %base-file-systems)) (firmware '()) (users (cons (user-account (name "alice") (comment "Bob's sister") (group "users") (supplementary-groups '("wheel" "audio" "video"))) %base-user-accounts)))) (define-syntax-rule (simple-operating-system user-services ...) "Return an operating system that includes USER-SERVICES in addition to %BASE-SERVICES." (operating-system (inherit %simple-os) (services (cons* user-services ... %base-services)))) ;;; ;;; Tests. ;;; (define-record-type* system-test make-system-test system-test? (name system-test-name) ;string (value system-test-value) ;%STORE-MONAD value (description system-test-description) ;string (location system-test-location (innate) ; (default (and=> (current-source-location) source-properties->location)))) (define (write-system-test test port) (match test (($ name _ _ ($ file line)) (format port "#" name file line (number->string (object-address test) 16))) (($ name) (format port "#" name (number->string (object-address test) 16))))) (set-record-type-printer! write-system-test) (define-gexp-compiler (compile-system-test (test ) system target) "Compile TEST to a derivation." (mparameterize %store-monad ((%current-system system) (%current-target-system target)) (system-test-value test))) (define (test-modules) "Return the list of modules that define system tests." (scheme-modules (dirname (search-path %load-path "guix.scm")) "gnu/tests" #:warn warn-about-load-error)) (define (fold-system-tests proc seed) "Invoke PROC on each system test, passing it the test and the previous result." (fold-module-public-variables (lambda (obj result) (if (system-test? obj) (cons obj result) result)) '() (test-modules))) (define (all-system-tests) "Return the list of system tests." (reverse (fold-system-tests cons '()))) ;; Local Variables: ;; eval: (put 'with-imported-modules-and-extensions 'scheme-indent-function 2) ;; End: ;;; tests.scm ends here