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

Correctly construct HEART_COMMAND and run_erl arguments #617

Merged
merged 3 commits into from
Oct 31, 2017
Merged

Correctly construct HEART_COMMAND and run_erl arguments #617

merged 3 commits into from
Oct 31, 2017

Conversation

lukebakken
Copy link
Contributor

@lukebakken lukebakken commented Oct 25, 2017

The runner script that ships with rebar builds HEART_COMMAND and run_erl arguments in such a way to preserve additional arguments the user may have passed:

https://github.com/rebar/rebar/blob/master/priv/templates/simplenode.runner#L215-L238

This PR preserves this behavior.

In addition, the current code on this line sets $@ but does not do anything with the result:

https://github.com/erlware/relx/blob/master/priv/templates/extended_bin#L481-L482

Investigated in response to this ML thread: http://erlang.org/pipermail/erlang-questions/2017-October/093974.html

The runner script that ships with rebar builds HEART_COMMAND and run_erl arguments that preserve additional arguments the user may have passed:

https://github.com/rebar/rebar/blob/master/priv/templates/simplenode.runner#L215-L238

This PR preserves this behavior. In additon, the current code on this line sets $@ but does not do anything with the result:

https://github.com/erlware/relx/blob/master/priv/templates/extended_bin#L481-L482

Investigated in response to this ML thread: http://erlang.org/pipermail/erlang-questions/2017-October/093974.html
@geib
Copy link

geib commented Oct 26, 2017

I originally reported the issue. I have confirmed the fix implemented by this pull request.

I cloned the rebar3 repo, checked out tag 3.3.6, my current version. Then I modified the rebar.config to use the relx branch in this pull request and built rebar3 escript. The rebar.config change was:

% {relx, "3.23.1"},
{relx, ".*", {git, "https://github.com/lukebakken/relx.git", {branch, "pass-arguments-to-run-erl"}}},

Next I built my project using the released rebar3, version 3.3.6. Running my application specifying a -config file resulted in the app starting but with the sys.config from the project. Shown here in the ps output:

geibs-MacBook-Pro:cse-cmd-processing geib$ _build/default/rel/cse-cmd-processing/bin/cse-cmd-processing start -config=/tmp/my_config
geibs-MacBook-Pro:cse-cmd-processing geib$ ps ax | grep beam
43346 s002 S+ 0:00.00 grep beam
43293 s003 Ss+ 0:01.20 /usr/local/lib/erlang/erts-7.3/bin/beam.smp -K true -A30 -- -root /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing -progname Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/bin/cse-cmd-processing -- -home /Users/geib -- -boot /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/releases/2.6.5-4/cse-cmd-processing -mode embedded -boot_var ERTS_LIB_DIR /usr/local/lib/erlang/lib -config /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/releases/2.6.5-4/sys.config -sname cse-cmd-processing -setcookie cse-cmd-processing_cookie -pa -- console

Then building release again, with relx fix included and re-running I get:

geibs-MacBook-Pro:cse-cmd-processing geib$ _build/default/rel/cse-cmd-processing/bin/cse-cmd-processing start -config=/tmp/my_config
geibs-MacBook-Pro:cse-cmd-processing geib$ ps ax | grep beam
43832 s002 S+ 0:00.00 grep beam
43779 s003 Ss+ 0:01.15 /usr/local/lib/erlang/erts-7.3/bin/beam.smp -K true -A30 -- -root /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing -progname Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/bin/cse-cmd-processing -- -home /Users/geib -- -boot /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/releases/2.6.5-4/cse-cmd-processing -mode embedded -boot_var ERTS_LIB_DIR /usr/local/lib/erlang/lib -config /Users/geib/git/cse.scb2.cmd_processing/cse-cmd-processing/_build/default/rel/cse-cmd-processing/releases/2.6.5-4/sys.config -sname cse-cmd-processing -setcookie cse-cmd-processing_cookie -pa -- console -config=/tmp/my_config #617

@lrascao
Copy link
Collaborator

lrascao commented Oct 26, 2017

Could you guys check if the smaller change i pushed gets the job done as well?

@lukebakken
Copy link
Contributor Author

lukebakken commented Oct 26, 2017

Hi @lrascao -

Part of my change is to address these lines, which use set -- to append $RUN_PARAM to the existing $@, which creates an "updated" $@ variable that then isn't used for anything (as far as I can tell).

Your set of changes also doesn't quote the contents of $@ which may or may not be necessary.

In my opinion, my original PR results in code that is easier to understand and is more in-line with the runner script that rebar shipped with, which I think we can assume has been widely tested.

@lrascao
Copy link
Collaborator

lrascao commented Oct 29, 2017

agreed, i'll try and whip up a test that ensures no future regressions when i get a chance

@lukebakken
Copy link
Contributor Author

@lrascao - I didn't notice there is a test suite. Have you started work? If not I will get a test added. I try to never submit a PR without a test 😄

@lrascao
Copy link
Collaborator

lrascao commented Oct 30, 2017

i have not, that would be much appreciated, the suite is test/rlx_extended_bin_SUITE

…ins both double quotes and a space character
@@ -642,28 +623,26 @@ case "$1" in
export EMU
export PROGNAME

# Store passed arguments since they will be erased by `set`
ARGS="$@"
Copy link
Contributor Author

@lukebakken lukebakken Oct 30, 2017

Choose a reason for hiding this comment

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

FYI, there is no way to preserve double-quotes and space characters and re-assign the positional parameter variable and correctly pass arguments to erlexec. Believe me, I tried. The side-effect of this is that the erlexec command must be included twice below - once for logging, and once "for real".

@lukebakken
Copy link
Contributor Author

@lrascao - all set. I added a test that demonstrates that the -goal_app baz '"bat zing"' argument is correctly passed through to the VM. I figured setting a string environment variable that contains a space is a sufficiently complex argument.

@lrascao
Copy link
Collaborator

lrascao commented Oct 30, 2017

the test seems to be failing on Linux, passes on Mac though

@lukebakken
Copy link
Contributor Author

Hmm I'll look into it. All of the tests run fine in my environment - up-to-date Arch Linux. I'll try it out on Ubuntu 14.

@lukebakken
Copy link
Contributor Author

@lrascao it's good that you test on Ubuntu, since dash is such a problematic shell. Everything appears to be addressed.

@lrascao lrascao merged commit fb91587 into erlware:master Oct 31, 2017
@lrascao
Copy link
Collaborator

lrascao commented Oct 31, 2017

cool! thanks a bunch!

@lukebakken lukebakken deleted the pass-arguments-to-run-erl branch October 31, 2017 14:52
@lukebakken
Copy link
Contributor Author

Awesome. Now I need to fix the issue in dash. If you're curious, the issue is with this printf:

ARGS="$(printf "\'%s\' " "$@")"

In a format string, \' should be output as ', since an escaped non-special character resolves to the character itself. Instead, dash ouputs \'.

Using \' is superfluous anyway, and was good to change to '. Still, dash should do the right thing.

Thanks again 😄

@lrascao
Copy link
Collaborator

lrascao commented Oct 31, 2017

👍

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.

3 participants