unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 4f7f2da0834afd20ca5993a3b1202008b5113653 3543 bytes (raw)
name: gnu/packages/patches/racket-rktio-bin-sh.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
From 070abbcc0d880ca4f97f997e096ac66650ccaaa0 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.

Guix should enable the special case by defining the C preprocessor
macro `GUIX_RKTIO_BIN_SH` with the path to `sh` in the store.
If:

    1. The `GUIX_RKTIO_BIN_SH` macro is defined; and

    2. `rktio_process` is called with the exact path "/bin/sh"; and

    3. The file specified by `GUIX_RKTIO_BIN_SH` exists;

then `rktio_process` will execute the file specified
by `GUIX_RKTIO_BIN_SH` instead of "/bin/sh".

Compared to previous attempts to patch the Racket sources,
making this change at the C level is both:

    - More comprehensive: it catches all attempts to execute "/bin/sh",
      without having to track down the source of every occurance; and

    - Less intrusive: by guarding the special case with a C preprocessor
      conditional and a runtime check that the file in the store exists,
      we make it much less likely that it will "leak" out of Guix.
---
 racket/src/rktio/rktio_process.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/racket/src/rktio/rktio_process.c b/racket/src/rktio/rktio_process.c
index fafaf728c1..0a319b381a 100644
--- a/racket/src/rktio/rktio_process.c
+++ b/racket/src/rktio/rktio_process.c
@@ -1301,12 +1301,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;
@@ -1333,6 +1335,23 @@ rktio_process_result_t *rktio_process(rktio_t *rktio,
   int i;
 #endif
 
+/* BEGIN PATCH for Guix */
+#if defined(GUIX_RKTIO_BIN_SH)
+# define GUIX_AS_a_STR_HELPER(x) #x
+# define GUIX_AS_a_STR(x) GUIX_AS_a_STR_HELPER(x)
+  /* A level of indirection makes `#` work as needed: */
+  command =
+      ((0 == strcmp(_guix_orig_command, "/bin/sh"))
+       && rktio_file_exists(rktio, GUIX_AS_a_STR(GUIX_RKTIO_BIN_SH)))
+      ? GUIX_AS_a_STR(GUIX_RKTIO_BIN_SH)
+      : _guix_orig_command;
+# undef GUIX_AS_a_STR
+# undef GUIX_AS_a_STR_HELPER
+#else
+  command = _guix_orig_command;
+#endif
+/* END PATCH for Guix */
+
   /* avoid compiler warnings: */
   to_subprocess[0] = -1;
   to_subprocess[1] = -1;

base-commit: 9d228d16fb99c274c964e5bef93e97333888769f
-- 
2.32.0


debug log:

solving 4f7f2da083 ...
found 4f7f2da083 in https://yhetil.org/guix-patches/5e5e8f491c7cbee3ef7a21437a52675dd47d186e.1659936550.git.philip@philipmcgrath.com/ ||
	https://yhetil.org/guix-patches/86c1205b1144c03620cce866e7d22c67d1e9c47d.1660215295.git.philip@philipmcgrath.com/
found 6bc2ee8331 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 6bc2ee8331f046959fd493f8e1604e682ddc4a0d	gnu/packages/patches/racket-minimal-sh-via-rktio.patch

applying [1/1] https://yhetil.org/guix-patches/5e5e8f491c7cbee3ef7a21437a52675dd47d186e.1659936550.git.philip@philipmcgrath.com/
diff --git a/gnu/packages/patches/racket-minimal-sh-via-rktio.patch b/gnu/packages/patches/racket-rktio-bin-sh.patch
similarity index 79%
rename from gnu/packages/patches/racket-minimal-sh-via-rktio.patch
rename to gnu/packages/patches/racket-rktio-bin-sh.patch
index 6bc2ee8331..4f7f2da083 100644

Checking patch gnu/packages/patches/racket-minimal-sh-via-rktio.patch => gnu/packages/patches/racket-rktio-bin-sh.patch...
Applied patch gnu/packages/patches/racket-minimal-sh-via-rktio.patch => gnu/packages/patches/racket-rktio-bin-sh.patch cleanly.

skipping https://yhetil.org/guix-patches/86c1205b1144c03620cce866e7d22c67d1e9c47d.1660215295.git.philip@philipmcgrath.com/ for 4f7f2da083
index at:
100644 4f7f2da0834afd20ca5993a3b1202008b5113653	gnu/packages/patches/racket-rktio-bin-sh.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).