forked from jruby/jruby-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunixlauncher.cpp
101 lines (82 loc) · 2.52 KB
/
unixlauncher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdlib.h>
#include <unistd.h>
#include "unixlauncher.h"
#include "utilsfuncs.h"
using namespace std;
extern "C" int nailgunClientMain(int argc, char *argv[], char *env[]);
UnixLauncher::UnixLauncher()
: ArgParser()
{
}
UnixLauncher::UnixLauncher(const UnixLauncher& orig)
: ArgParser(orig)
{
}
UnixLauncher::~UnixLauncher() {
}
int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
platformDir = argv[0];
if (!initPlatformDir() || !parseArgs(argc - 1, argv + 1)) {
return 255;
}
if (nailgunClient) {
progArgs.push_front("org.jruby.util.NailMain");
char ** nailArgv = convertToArgvArray(progArgs);
int nailArgc = progArgs.size();
if (printCommandLine) {
printListToConsole(progArgs);
for (int i = 0; i < nailArgc; i++) {
free(nailArgv[i]);
}
delete[] nailArgv;
return 0;
}
return nailgunClientMain(progArgs.size(), (char**)nailArgv, envp);
}
string java("");
if (getenv("JAVACMD") != NULL) {
java = getenv("JAVACMD");
} else {
if (!jdkhome.empty()) {
java = jdkhome + "/bin/java";
} else if (getenv("JAVA_HOME") != NULL) {
string java_home = string(getenv("JAVA_HOME"));
jdkhome = java_home;
java_home = trimTrailingBackslashes(java_home);
java = java_home + "/bin/java";
} else {
java = findOnPath("java");
}
}
if (java.empty()) {
printToConsole("No `java' executable found on PATH.");
return 255;
}
prepareOptions();
list<string> commandLine;
commandLine.push_back(java);
addOptionsToCommandLine(commandLine);
logMsg("Command line:");
for (list<string>::iterator it = commandLine.begin(); it != commandLine.end(); ++it) {
logMsg("\t%s", it->c_str());
}
char** newArgv = convertToArgvArray(commandLine);
int newArgc = commandLine.size();
if (printCommandLine) {
printListToConsole(commandLine);
for (int i = 0; i < newArgc; i++) {
free(newArgv[i]);
}
delete[] newArgv;
return 0;
}
if (!fileExists(java.c_str())) {
string msg = "No `java' exists at " + java + ", please double-check JAVA_HOME.\n";
printToConsole(msg.c_str());
return 255;
}
execv(java.c_str(), newArgv);
// shouldn't get here unless something bad happened with execv
logErr(true, true, "execv failed:");
return 255;
}