summaryrefslogtreecommitdiff
path: root/lib/gitlab/popen.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/popen.rb
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
downloadgitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/popen.rb')
-rw-r--r--lib/gitlab/popen.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/popen.rb b/lib/gitlab/popen.rb
index 7fa00d0c68c..586b271c4d0 100644
--- a/lib/gitlab/popen.rb
+++ b/lib/gitlab/popen.rb
@@ -10,10 +10,19 @@ module Gitlab
Result = Struct.new(:cmd, :stdout, :stderr, :status, :duration)
# Returns [stdout + stderr, status]
+ # status is either the exit code or the signal that killed the process
def popen(cmd, path = nil, vars = {}, &block)
result = popen_with_detail(cmd, path, vars, &block)
- ["#{result.stdout}#{result.stderr}", result.status&.exitstatus]
+ # Process#waitpid returns Process::Status, which holds a 16-bit value.
+ # The higher-order 8 bits hold the exit() code (`exitstatus`).
+ # The lower-order bits holds whether the process was terminated.
+ # If the process didn't exit normally, `exitstatus` will be `nil`,
+ # but we still want a non-zero code, even if the value is
+ # platform-dependent.
+ status = result.status&.exitstatus || result.status.to_i
+
+ ["#{result.stdout}#{result.stderr}", status]
end
# Returns Result