guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/45: environment: Report "command not found" from the child process.


From: guix-commits
Subject: 03/45: environment: Report "command not found" from the child process.
Date: Thu, 4 Aug 2022 06:07:06 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit ae1f12018112573bf142596b78d75dbfd723d859
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Aug 4 11:13:48 2022 +0200

    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.
---
 guix/scripts/environment.scm | 27 ++++++++++-----------------
 1 file 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]