Hello, Justin Veilleux <terramor...@cock.li> skribis:
> Hi. I thought it would be interesting to have a shepherd service run a > repl like in > https://www.gnu.org/software/shepherd/manual/html_node/REPL-Service.html. > Since there is no shepherd repl service in a (gnu services *) module, I > created a shepherd-service-type and shepherd-service (I copied the code > from `(shepherd service repl)`) Another option is to turn it on only when you need it, along these lines: herd eval root '(begin (use-modules (shepherd service repl)) (register-services (list (repl-service))))' herd start repl (Granted, it’s not as convenient.) > The `reconfigure` runs and after fiddling with permission bits and > connecting to the socket through emacs and geiser (like in the manual), > I am able to execute expressions such as `(+ 2 2)` and `(display > "test\n")` and everything works as expected. > > However, when I try to evaluate `lookup-service` (without calling it), > the repl gets stuck in an infinite loop of > >> scheme@(shepherd-user) [1]> While reading expression: >> Attempt to suspend fiber within continuation barrier Yes: --8<---------------cut here---------------start------------->8--- scheme@(shepherd-user)> (+ 2 3) $6 = 5 scheme@(shepherd-user)> (lookup-service 'repl) ;;; socket:56:1: warning: possibly unbound variable `lookup-service' ice-9/boot-9.scm:1685:16: In procedure raise-exception: Unbound variable: lookup-service Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(shepherd-user) [1]> While reading expression: Attempt to suspend fiber within continuation barrier scheme@(shepherd-user) [1]> While reading expression: Attempt to suspend fiber within continuation barrier --8<---------------cut here---------------end--------------->8--- The problem here is that the exception is raised C code (in libguile/modules.c, then indirectly calling ‘scm_error’), which makes it a “continuation barrier” (meaning that it prevents Fibers from switching contexts among fibers in the shepherd process, hence the error above.) The same goes for many exceptions launched from libguile primitives (for instance division by zero), but it’s fine if we take a C-free path: --8<---------------cut here---------------start------------->8--- scheme@(shepherd-user)> (raise-exception 123) ice-9/boot-9.scm:1685:16: In procedure raise-exception: Throw to key `%exception' with args `(123)'. Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(shepherd-user) [1]> ,bt In ice-9/boot-9.scm: 1685:16 0 (raise-exception _ #:continuable? _) scheme@(shepherd-user) [1]> ,q scheme@(shepherd-user)> (+ 1 2) $31 = 3 --8<---------------cut here---------------end--------------->8--- And of course it’s all good when there are no exceptions: --8<---------------cut here---------------start------------->8--- scheme@(shepherd-user)> ,use(shepherd service) scheme@(shepherd-user)> (lookup-service 'repl) $12 = #<<service> 7fbd052fabd0> scheme@(shepherd-user)> (lookup-service 'root) $13 = #<<service> 7fbd056fd1c0> scheme@(shepherd-user)> (service-status $12) $14 = running scheme@(shepherd-user)> (service-status-changes $12) $15 = ((running . 1704838523) (starting . 1704838523)) --8<---------------cut here---------------end--------------->8--- This is undoubtedly a shortcoming for the REPL. The solution here would be to arrange for Guile primitives to raise exceptions through a different path somehow. Not sure how. Thanks, Ludo’.