erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
697 stars 232 forks source link

`cd "$ROOTDIR"` before any `erl` subscript runs in extended_bin #876

Open kubantsev opened 3 years ago

kubantsev commented 3 years ago

When using -sname node0 without hostname in vm.args and run relbin under sudo, script's fun relx_get_nodename fails with inconsistent CWD:

[user@host] ~ » sudo -H -u test /opt/vendor/product/bin/relbin ping
…
+ NAME=node0@#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: .. Function: read_file_info. Process: code_server."}
#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: ./maps.beam. Function: get_file. Process: code_server."}
#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: ./inet_db.beam. Function: get_file. Process: code_server."}
#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: ./inet_config.beam. Function: get_file. Process: code_server."}
#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: ./inet_udp.beam. Function: get_file. Process: code_server."}
#{label=>{erl_prim_loader,file_error},report=>"File operation error: eacces. Target: ./inet.beam. Function: get_file. Process: code_server."}
…

line 700:

# User can specify an sname without @hostname
# This will fail when creating remote shell
# So here we check for @ and add @hostname if missing
case "${NAME}" in
    *@*) ;;                             # Nothing to do
    *)   NAME=${NAME}@$(relx_get_nodename);;  # Add @hostname
esac

# Export the variable so that it's available in the 'eval' calls
export NAME

# create a variable of just the hostname part of the nodename
RELX_HOSTNAME=$(echo "${NAME}" | cut -d'@' -f2)

test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/'
PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}"

cd "$ROOTDIR"
tsloughter commented 3 years ago

Why do you say it is an inconsistent cwd?

If I'm reading the output right it seems there is a bug in the script, it is not properly exit'ing when relx_get_nodename fails, but instead setting the nodename to be the error message?

But the other issue looks like it can't read the beam files? You are trying to run the release as root?

tsloughter commented 3 years ago

Oh, you are trying to run as user test. Does test have permission to read the beam files?