Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Get bundle exec respecting proc titles #7140

Merged
1 commit merged into from
Apr 29, 2019
Merged

Get bundle exec respecting proc titles #7140

1 commit merged into from
Apr 29, 2019

Conversation

deivid-rodriguez
Copy link
Member

@deivid-rodriguez deivid-rodriguez commented Apr 24, 2019

What was the end-user problem that led to this PR?

The problem was that bundle exec would not respect custom proctitles inside scripts.

What was your diagnosis of the problem?

My diagnosis was that the previous code was using the third form of Kernel.exec, documented as:

In the third form (exec(["command", "argv0"], "arg1", ...)), starting a two-element array at the beginning of the command, the first element is the command to be executed, and the second argument is used as the argv[0] value, which may show up in process listings.

See https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-exec.

However, since this form messes with proc titles, it seems to affect scripts settting their own proc titles.

What is your fix for the problem, implemented in this PR?

My fix is to use the simpler form:

In the second form (exec("command1", "arg1", ...)), the first is taken as a command name and the rest are passed as parameters to command with no shell expansion.

We were not passing any special proc title, so I don't think we need the third form, and this simpler form allows custom proc titles inside scripts to work just fine.

Why did you choose this fix out of the possible options?

I chose this fix because I couldn't figure out a better one.

Closes #7135.

@duckinator
Copy link
Member

This definitely seems like the right approach to me.

@@ -55,6 +55,13 @@
expect(out).to eq("hi")
end

it "respects custom process title when loading through ruby" do
create_file "Gemfile"
create_file "a.rb", 'Process.setproctitle("1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16"); puts `ps -eo args | grep [1]-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16`'
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm shelling out to ps in order to test this, since I couldn't think of a better way.

Copy link
Member

Choose a reason for hiding this comment

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

I can't think of another way to do it, either. It may be worth adding a brief comment explaining how it's testing it, for folks less familiar with *nix tools.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I'll add a little comment. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a local variable with a long name, to explain what the test script is about 😃

@deivid-rodriguez
Copy link
Member Author

Thanks for having a look @duckinator. I'll get this in!

@bundlerbot r+

ghost pushed a commit that referenced this pull request Apr 29, 2019
7140: Get `bundle exec` respecting proc titles r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was that `bundle exec` would not respect custom proctitles inside scripts.

### What was your diagnosis of the problem?

My diagnosis was that the previous code was using the third form of `Kernel.exec`, documented as:

> In the third form (exec(["command", "argv0"], "arg1", ...)), starting a two-element array at the beginning of the command, the first element is the command to be executed, and the second argument is used as the argv[0] value, which may show up in process listings.

See https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-exec.

However, since this form messes with proc titles, it seems to affect scripts settting their own proc titles.

### What is your fix for the problem, implemented in this PR?

My fix is to use the simpler form:

> In the second form (exec("command1", "arg1", ...)), the first is taken as a command name and the rest are passed as parameters to command with no shell expansion.

We were not passing any special proc title, so I don't think we need the third form, and this simpler form allows custom proc titles inside scripts to work just fine.

### Why did you choose this fix out of the possible options?

I chose this fix because I couldn't figure out a better one.

Closes #7135.

Co-authored-by: David Rodríguez <[email protected]>
@ghost
Copy link

ghost commented Apr 29, 2019

Build succeeded

@ghost ghost merged commit a7d5467 into master Apr 29, 2019
@ghost ghost deleted the fix_exec_proc_title branch April 29, 2019 21:58
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cropped process title visible with htop/ps when using Process.setproctitle
2 participants