summaryrefslogtreecommitdiff
path: root/guix/scripts
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-08-04 11:13:48 +0200
committerLudovic Courtès <ludo@gnu.org>2022-08-04 12:05:46 +0200
commitae1f12018112573bf142596b78d75dbfd723d859 (patch)
tree005cc487db26b3631b10f46335fe9fd935a58c46 /guix/scripts
parent18e00988176162ac736c873dc6cb06169b0aaa3b (diff)
downloadguix-patches-ae1f12018112573bf142596b78d75dbfd723d859.tar
guix-patches-ae1f12018112573bf142596b78d75dbfd723d859.tar.gz
environment: Report "command not found" from the child process.
Fixes a bug whereby, for example: guix shell bash -- bash -c xyz would erroneously print: guix shell: error: bash: command not found simply because the parent process could not distinguish that 127 from a "genuine" 127 used by convention for "command not found". * guix/scripts/environment.scm (launch-environment): Before exiting, report a "command not found" error and suggest a command name. (validate-exit-status): Remove. (launch-environment/fork): Remove call (launch-environment/container)[exit/status*]: Remove. Call 'exit/status' instead of it.
Diffstat (limited to 'guix/scripts')
-rw-r--r--guix/scripts/environment.scm27
1 files changed, 10 insertions, 17 deletions
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 3216235937..2493134470 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -408,7 +408,14 @@ regexps in WHITE-LIST."
(lambda ()
(apply execlp program program args))
(lambda _
- ;; Following established convention, exit with 127 upon ENOENT.
+ ;; Report the error from here because the parent process cannot
+ ;; distinguish between the conventional 127 exit code and a process
+ ;; that exited with 127 for other reasons (e.g., "sh -c xyz").
+ (report-error (G_ "~a: command not found~%") program)
+ (suggest-command-name profile command)
+
+ ;; Following established convention, exit with 127 (aka. EX_NOTFOUND)
+ ;; upon ENOENT.
(primitive-_exit 127))))))
(define (child-shell-environment shell profile manifest)
@@ -581,17 +588,6 @@ command name."
(display-hint (format #f (G_ "Did you mean '~a'?~%")
closest)))))))))
-(define (validate-exit-status profile command status)
- "When STATUS, an integer as returned by 'waitpid', is 127, raise a \"command
-not found\" error. Otherwise return STATUS."
- ;; Most likely, exit value 127 means ENOENT.
- (when (eqv? (status:exit-val status) 127)
- (report-error (G_ "~a: command not found~%")
- (first command))
- (suggest-command-name profile command)
- (exit 1))
- status)
-
(define* (launch-environment/fork command profile manifest
#:key pure? (white-list '()))
"Run COMMAND in a new process with an environment containing PROFILE, with
@@ -604,7 +600,7 @@ regexps in WHITE-LIST."
#:white-list white-list))
(pid (match (waitpid pid)
((_ . status)
- (validate-exit-status profile command status))))))
+ status)))))
(define* (launch-environment/container #:key command bash user user-mappings
profile manifest link-profile? network?
@@ -625,9 +621,6 @@ WHILE-LIST."
(and (file-exists? (file-system-mapping-source mapping))
(file-system-mapping->bind-mount mapping)))
- (define (exit/status* status)
- (exit/status (validate-exit-status profile command status)))
-
(mlet %store-monad ((reqs (inputs->requisites
(list (direct-store-path bash) profile))))
(return
@@ -684,7 +677,7 @@ WHILE-LIST."
'())
(map file-system-mapping->bind-mount
mappings))))
- (exit/status*
+ (exit/status
(call-with-container file-systems
(lambda ()
;; Setup global shell.