diff options
author | Lukas Larsson <[email protected]> | 2016-06-27 18:40:36 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2016-07-01 11:19:43 +0200 |
commit | 412d7dfcfb667bb2b329b8e35c929c2b5abcc2b1 (patch) | |
tree | 254123c6369498ce05e65e5fc78a543ec6551eec /erts/emulator/sys/unix/erl_child_setup.c | |
parent | 3411d9e13bd8a4b3aee530d8f66b5118e14e447b (diff) | |
download | otp-412d7dfcfb667bb2b329b8e35c929c2b5abcc2b1.tar.gz otp-412d7dfcfb667bb2b329b8e35c929c2b5abcc2b1.tar.bz2 otp-412d7dfcfb667bb2b329b8e35c929c2b5abcc2b1.zip |
erts: Fix spawn driver with relative cd option
Diffstat (limited to 'erts/emulator/sys/unix/erl_child_setup.c')
-rw-r--r-- | erts/emulator/sys/unix/erl_child_setup.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/erts/emulator/sys/unix/erl_child_setup.c b/erts/emulator/sys/unix/erl_child_setup.c index 219ca98c71..fa4750a6e9 100644 --- a/erts/emulator/sys/unix/erl_child_setup.c +++ b/erts/emulator/sys/unix/erl_child_setup.c @@ -127,7 +127,7 @@ start_new_child(int pipes[]) int size, res, i, pos = 0; char *buff, *o_buff; - char *cmd, *wd, **new_environ, **args = NULL; + char *cmd, *cwd, *wd, **new_environ, **args = NULL; Sint32 cnt, flags; @@ -170,6 +170,10 @@ start_new_child(int pipes[]) cmd = buff; buff += strlen(buff) + 1; + + cwd = buff; + buff += strlen(buff) + 1; + if (*buff == '\0') { wd = NULL; } else { @@ -222,17 +226,29 @@ start_new_child(int pipes[]) ASSERT(res == sizeof(proto)); } } while(res < 0 && (errno == EINTR || errno == ERRNO_BLOCK)); + if (res < 1) { errno = EPIPE; errln = __LINE__; goto child_error; } + DEBUG_PRINT("Set cwd to: '%s'",cwd); + + if (chdir(cwd) < 0) { + /* This is not good, it probably means that the cwd of + beam is invalid. We ignore it and try anyways as + the child might now need a cwd or the chdir below + could take us to a valid directory. + */ + } + DEBUG_PRINT("Set wd to: '%s'",wd); if (wd && chdir(wd) < 0) { - errln = __LINE__; - goto child_error; + int err = errno; + fprintf(stderr,"spawn: Could not cd to %s\r\n", wd); + _exit(err); } DEBUG_PRINT("Do that forking business: '%s'",cmd); |