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

escript: Handle symbolic link to a standalone escript #1293

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions erts/etc/common/escript.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,6 @@ main(int argc, char** argv)
argv[argc] = NULL;
#endif

emulator = env = get_env("ESCRIPT_EMULATOR");
if (emulator == NULL) {
emulator = get_default_emulator(argv[0]);
}

if (strlen(emulator) >= PMAX)
error("Value of environment variable ESCRIPT_EMULATOR is too large");

/*
* Allocate the argv vector to be used for arguments to Erlang.
* Arrange for starting to pushing information in the middle of
Expand All @@ -446,21 +438,10 @@ main(int argc, char** argv)
eargv_base = (char **) emalloc(eargv_size*sizeof(char*));
eargv = eargv_base;
eargc = 0;
push_words(emulator);
eargc_base = eargc;
eargv = eargv + eargv_size/2;
eargc = 0;

free_env_val(env);

/*
* Push initial arguments.
*/

PUSH("+B");
PUSH2("-boot", "start_clean");
PUSH("-noshell");

/* Determine basename of the executable */
for (basename = argv[0]+strlen(argv[0]);
basename > argv[0] && !(IS_DIRSEP(basename[-1]));
Expand Down Expand Up @@ -510,6 +491,27 @@ main(int argc, char** argv)
efree(absname);
}

/* Determine path to emulator */
emulator = env = get_env("ESCRIPT_EMULATOR");

if (emulator == NULL) {
emulator = get_default_emulator(scriptname);
}

if (strlen(emulator) >= PMAX)
error("Value of environment variable ESCRIPT_EMULATOR is too large");

/*
* Push initial arguments.
*/

push_words(emulator);
free_env_val(env);

PUSH("+B");
PUSH2("-boot", "start_clean");
PUSH("-noshell");

/*
* Read options from the %%! row in the script and add them as args
*/
Expand Down