From 5f3fc12bf123f30485800960b0493f5dd538d107 Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Thu, 19 May 2022 13:41:56 -0400 Subject: [PATCH] Chez Scheme: patch s_process for "/bin/sh" on Guix This patch reuses the C preprocessor macro `GUIX_RKTIO_BIN_SH` from a previous patch. If: 1. The `GUIX_RKTIO_BIN_SH` macro is defined; and 2. The path specified by `GUIX_RKTIO_BIN_SH` exists; then `s_process` will call `execl` with the file specified by `GUIX_RKTIO_BIN_SH` instead of "/bin/sh". This patch does not change the behavior of `s_system`, which relies on `system` from the C library. --- racket/src/ChezScheme/c/prim5.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/racket/src/ChezScheme/c/prim5.c b/racket/src/ChezScheme/c/prim5.c index f5e3e345be..9db2989138 100644 --- a/racket/src/ChezScheme/c/prim5.c +++ b/racket/src/ChezScheme/c/prim5.c @@ -856,6 +856,22 @@ static ptr s_process(s, stderrp) char *s; IBOOL stderrp; { INT tofds[2], fromfds[2], errfds[2]; struct sigaction act, oint_act; + /* 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: */ + struct stat guix_stat_buf; + char *guix_sh = + (0 == stat(GUIX_AS_a_STR(GUIX_RKTIO_BIN_SH), &guix_stat_buf)) + ? GUIX_AS_a_STR(GUIX_RKTIO_BIN_SH) + : "/bin/sh"; +# undef GUIX_AS_a_STR +# undef GUIX_AS_a_STR_HELPER +#else /* GUIX_RKTIO_BIN_SH */ + char *guix_sh = "/bin/sh"; +#endif + /* END PATCH for Guix */ if (pipe(tofds)) S_error("process","cannot open pipes"); if (pipe(fromfds)) { @@ -881,7 +897,9 @@ static ptr s_process(s, stderrp) char *s; IBOOL stderrp; { CLOSE(1); if (dup(fromfds[1]) != 1) _exit(1); CLOSE(2); if (dup(stderrp ? errfds[1] : 1) != 2) _exit(1); {INT i; for (i = 3; i < NOFILE; i++) (void)CLOSE(i);} - execl("/bin/sh", "/bin/sh", "-c", s, NULL); + /* BEGIN PATCH for Guix */ + execl(guix_sh, guix_sh, "-c", s, NULL); + /* END PATCH for Guix */ _exit(1) /* only if execl fails */; /*NOTREACHED*/ } else { base-commit: 9d228d16fb99c274c964e5bef93e97333888769f -- 2.32.0