Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raises on failure to run a process (Fixes #3517) #3520

Conversation

lbguilherme
Copy link
Contributor

@lbguilherme lbguilherme commented Nov 8, 2016

This changes the behavior of Process.new to block until execvp is performed and raise an exception if it fails. Previous behavior was to return immediately and let the forked process exit with 127. See #3517.

Before:

it "returns status 127 if command could not be executed" do
  process = Process.new("foobarbaz")
  process.wait.exit_code.should eq(127)
end

After:

it "raises if command could not be executed" do
  expect_raises Errno do
    Process.new("foobarbaz")
  end
end

@Sija
Copy link
Contributor

Sija commented Nov 22, 2016

GTG?

@Sija
Copy link
Contributor

Sija commented Jan 6, 2017

@asterite ping?

Copy link
Member

@RX14 RX14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be merged but the implementation should be improved.

@@ -240,14 +244,24 @@ class Process
fork_error || error,
chdir
)
rescue ex : Errno
value = ex.errno
child_sock.write(Bytes.new(pointerof(value).as(UInt8*), 4))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use write_bytes.

ensure
LibC._exit 127
end
end

child_sock.close
slice = Bytes.new(4)
if parent_sock.read(slice) == 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use read_bytes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, read_bytes calls read_fully which raises when the pipe is closed. Would need read_bytes? for that.

slice = Bytes.new(4)
if parent_sock.read(slice) == 4
parent_sock.close
Errno.value = slice.pointer(4).as(Int32*).value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you just pass the value to Errno's constructor instead of setting Errno.value?

@sdogruyol
Copy link
Member

Any update on this?

@bew
Copy link
Contributor

bew commented Jun 4, 2018

@lbguilherme will you continue working on this PR?

@Sija
Copy link
Contributor

Sija commented Jul 1, 2018

@lbguilherme 🏓

@RX14
Copy link
Member

RX14 commented Aug 7, 2018

Would be great if someone from the community could pick up this abandoned PR

@Sija
Copy link
Contributor

Sija commented Aug 8, 2018

Can be closed since #6501 was merged.

@bcardiff bcardiff closed this Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants