Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set working directory in SpawnPreparer because bashrc can change it. …

…Fixes issue #851
  • Loading branch information...
commit 6f507ec700b708756dc829489009ec25aab06356 1 parent 259b89f
@FooBarWidget FooBarWidget authored
View
7 ext/common/ApplicationPool2/DirectSpawner.h
@@ -109,7 +109,9 @@ class DirectSpawner: public Spawner {
startBackgroundThread(detachProcessMain, (void *) (long) pid);
}
- vector<string> createCommand(const Options &options, shared_array<const char *> &args) const {
+ vector<string> createCommand(const Options &options, const SpawnPreparationInfo &preparation,
+ shared_array<const char *> &args) const
+ {
vector<string> startCommandArgs;
string agentsDir = resourceLocator.getAgentsDir();
vector<string> command;
@@ -129,6 +131,7 @@ class DirectSpawner: public Spawner {
command.push_back(agentsDir + "/SpawnPreparer");
}
command.push_back(agentsDir + "/SpawnPreparer");
+ command.push_back(preparation.appRoot);
command.push_back(serializeEnvvarsFromPoolOptions(options));
command.push_back(startCommandArgs[0]);
// Note: do not try to set a process title here.
@@ -166,8 +169,8 @@ class DirectSpawner: public Spawner {
possiblyRaiseInternalError(options);
shared_array<const char *> args;
- vector<string> command = createCommand(options, args);
SpawnPreparationInfo preparation = prepareSpawn(options);
+ vector<string> command = createCommand(options, preparation, args);
SocketPair adminSocket = createUnixSocketPair();
Pipe errorPipe = createPipe();
DebugDirPtr debugDir = make_shared<DebugDir>(preparation.uid, preparation.gid);
View
3  ext/common/ApplicationPool2/SmartSpawner.h
@@ -120,6 +120,7 @@ class SmartSpawner: public Spawner, public enable_shared_from_this<SmartSpawner>
command.push_back(agentsDir + "/SpawnPreparer");
}
command.push_back(agentsDir + "/SpawnPreparer");
+ command.push_back(preparation.appRoot);
command.push_back(serializeEnvvarsFromPoolOptions(options));
command.push_back(preloaderCommand[0]);
// Note: do not try to set a process title here.
@@ -210,8 +211,8 @@ class SmartSpawner: public Spawner, public enable_shared_from_this<SmartSpawner>
checkChrootDirectories(options);
shared_array<const char *> args;
- vector<string> command = createRealPreloaderCommand(options, args);
preparation = prepareSpawn(options);
+ vector<string> command = createRealPreloaderCommand(options, args);
SocketPair adminSocket = createUnixSocketPair();
Pipe errorPipe = createPipe();
DebugDirPtr debugDir = make_shared<DebugDir>(preparation.uid, preparation.gid);
View
28 ext/common/agents/SpawnPreparer.cpp
@@ -25,6 +25,22 @@ extern "C" {
}
static void
+changeWorkingDir(const char *dir) {
+ int ret = chdir(dir);
+ if (ret == 0) {
+ setenv("PWD", dir, 1);
+ } else {
+ int e = errno;
+ printf("!> Error\n");
+ printf("!> \n");
+ printf("Unable to change working directory to '%s': %s (errno=%d)\n",
+ dir, strerror(e), e);
+ fflush(stdout);
+ exit(1);
+ }
+}
+
+static void
setGivenEnvVars(const char *envvarsData) {
string envvars = Base64::decode(envvarsData);
const char *key = envvars.data();
@@ -144,18 +160,20 @@ dumpInformation() {
#endif
}
-// Usage: SpawnPreparer <envvars> <executable> <exec args...>
+// Usage: SpawnPreparer <working directory> <envvars> <executable> <exec args...>
int
main(int argc, char *argv[]) {
- if (argc < 4) {
+ if (argc < 5) {
fprintf(stderr, "Too few arguments.\n");
exit(1);
}
- const char *envvars = argv[1];
- const char *executable = argv[2];
- char **execArgs = &argv[3];
+ const char *workingDir = argv[1];
+ const char *envvars = argv[2];
+ const char *executable = argv[3];
+ char **execArgs = &argv[4];
+ changeWorkingDir(workingDir);
setGivenEnvVars(envvars);
dumpInformation();
Please sign in to comment.
Something went wrong with that request. Please try again.