Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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