erlware / relx

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

extended_bin does not account for cookie being set in an extended vm.args #904

Open artman41 opened 2 years ago

artman41 commented 2 years ago

If I have 2 vm.args files where 1 of the files inherits the cookie from a different file:

file1.vm.args

-cookie test_cookie

file2.vm.args

-args_file file1.vm.args

Then the following line in extended_bin will not work and will instead use the cookie in ~/.erlang.cookie https://github.com/erlware/relx/blob/d2add7c2fdaa9a26bddfb40455b2000abc16b0c6/priv/templates/extended_bin#L723-L740

Even though the recursion is validated a few lines prior https://github.com/erlware/relx/blob/d2add7c2fdaa9a26bddfb40455b2000abc16b0c6/priv/templates/extended_bin#L612-L661

tsloughter commented 2 years ago

Thanks, yea, I guess we need to utilize the files array to check all of them for everything (not just COOKIE, but dist args too).

artman41 commented 2 years ago

@tsloughter just wrote this function which I'm going to put copy into our extended_bin after relx creates it, I'm thinking it can replace the call on line 728, any use?

function get_cookie() {
    local vm_args_file="$1";
    if [[ -z "$vm_args_file" ]]; then
        echo 'vm_args_file was empty!' >&2;
        exit 1;
    fi;
    local cookie="$(grep '^-setcookie' $vm_args_file)";
    for args_file in $(grep '^-args_file' $vm_args_file | awk  '{print $2}'); do
        local new_cookie="$(get_cookie $args_file)";
        if [[ -n "$new_cookie" ]]; then
            cookie=$new_cookie;
        fi;
    done;
    echo $cookie;
}