container: Correctly report exit status.
* gnu/build/linux-container.scm (container-excursion): Return the raw
status value.
* tests/containers.scm ("container-excursion, same namespaces"): Add
'status:exit-val' call.
* guix/scripts/container/exec.scm (guix-container-exec): Correctly
handle the different cases.
			
			
This commit is contained in:
		
							parent
							
								
									17448c8afa
								
							
						
					
					
						commit
						52eb3db19c
					
				
					 3 changed files with 15 additions and 6 deletions
				
			
		| 
						 | 
					@ -404,7 +404,7 @@ load path must be adjusted as needed."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (container-excursion pid thunk)
 | 
					(define (container-excursion pid thunk)
 | 
				
			||||||
  "Run THUNK as a child process within the namespaces of process PID and
 | 
					  "Run THUNK as a child process within the namespaces of process PID and
 | 
				
			||||||
return the exit status."
 | 
					return the exit status, an integer as returned by 'waitpid'."
 | 
				
			||||||
  (define (namespace-file pid namespace)
 | 
					  (define (namespace-file pid namespace)
 | 
				
			||||||
    (string-append "/proc/" (number->string pid) "/ns/" namespace))
 | 
					    (string-append "/proc/" (number->string pid) "/ns/" namespace))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -436,7 +436,7 @@ return the exit status."
 | 
				
			||||||
    (pid
 | 
					    (pid
 | 
				
			||||||
     (match (waitpid pid)
 | 
					     (match (waitpid pid)
 | 
				
			||||||
       ((_ . status)
 | 
					       ((_ . status)
 | 
				
			||||||
        (status:exit-val status))))))
 | 
					        status)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (container-excursion* pid thunk)
 | 
					(define (container-excursion* pid thunk)
 | 
				
			||||||
  "Like 'container-excursion', but return the return value of THUNK."
 | 
					  "Like 'container-excursion', but return the return value of THUNK."
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -102,4 +102,12 @@ and the other containing arguments for the command to be executed."
 | 
				
			||||||
                                       environment)
 | 
					                                       environment)
 | 
				
			||||||
                             (apply execlp program program program-args)))))))
 | 
					                             (apply execlp program program program-args)))))))
 | 
				
			||||||
          (unless (zero? result)
 | 
					          (unless (zero? result)
 | 
				
			||||||
            (leave (G_ "exec failed with status ~d~%") result)))))))
 | 
					            (match (status:exit-val result)
 | 
				
			||||||
 | 
					              (#f
 | 
				
			||||||
 | 
					               (if (status:term-sig result)
 | 
				
			||||||
 | 
					                   (leave (G_ "process terminated with signal ~a~%")
 | 
				
			||||||
 | 
					                          (status:term-sig result))
 | 
				
			||||||
 | 
					                   (leave (G_ "process stopped with signal ~a~%")
 | 
				
			||||||
 | 
					                          (status:stop-sig result))))
 | 
				
			||||||
 | 
					              (code
 | 
				
			||||||
 | 
					               (leave (G_ "process exited with status ~d~%") code)))))))))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -203,9 +203,10 @@
 | 
				
			||||||
  42
 | 
					  42
 | 
				
			||||||
  ;; The parent and child are in the same namespaces.  'container-excursion'
 | 
					  ;; The parent and child are in the same namespaces.  'container-excursion'
 | 
				
			||||||
  ;; should notice that and avoid calling 'setns' since that would fail.
 | 
					  ;; should notice that and avoid calling 'setns' since that would fail.
 | 
				
			||||||
  (container-excursion (getpid)
 | 
					  (status:exit-val
 | 
				
			||||||
    (lambda ()
 | 
					   (container-excursion (getpid)
 | 
				
			||||||
      (primitive-exit 42))))
 | 
					     (lambda ()
 | 
				
			||||||
 | 
					       (primitive-exit 42)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(skip-if-unsupported)
 | 
					(skip-if-unsupported)
 | 
				
			||||||
(test-assert "container-excursion*"
 | 
					(test-assert "container-excursion*"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue