Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2007-07-24 15:05:37 -0400
committerAndrew Niefer2007-07-24 15:05:37 -0400
commite2e3c706503b04f55a8bdc8bb8caef895ae1fb70 (patch)
tree7536ea40208c54bb973411e84d67be8583bf0cb1 /bundles/org.eclipse.equinox.executable
parentaafa6e6ba60701d8ef47d83f8814ebb4119d1329 (diff)
downloadrt.equinox.framework-e2e3c706503b04f55a8bdc8bb8caef895ae1fb70.tar.gz
rt.equinox.framework-e2e3c706503b04f55a8bdc8bb8caef895ae1fb70.tar.xz
rt.equinox.framework-e2e3c706503b04f55a8bdc8bb8caef895ae1fb70.zip
bug 195384
Diffstat (limited to 'bundles/org.eclipse.equinox.executable')
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipse.c73
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseNix.c70
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseOS.h4
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseUtil.c44
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseUtil.h8
-rw-r--r--bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c48
-rw-r--r--bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp47
7 files changed, 167 insertions, 127 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipse.c b/bundles/org.eclipse.equinox.executable/library/eclipse.c
index 7db0b309d..21e8d9e1f 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipse.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipse.c
@@ -1394,3 +1394,76 @@ static int processEEProps(_TCHAR* eeFile)
free(eeDir);
return 0;
}
+
+/* returns an array of paths that should be place on the search path for loading
+ * the vm shared libraries.
+ * Each entry is terminated with the platform path separator.
+ * Entries are either from the ee.library.path or calculated from the path to the
+ * vm shared library itself.
+ */
+_TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary) {
+ _TCHAR ** paths = NULL;
+ _TCHAR * buffer = NULL;
+ _TCHAR * path, * entry, *c;
+ _TCHAR separator;
+ int numPaths = 2;
+ int i;
+
+ buffer = (eeLibPath != NULL) ? _tcsdup(eeLibPath) : _tcsdup(vmLibrary);
+#ifdef WIN32
+ /* On windows we sometimes get '/' instead of '\', just always use '/' */
+ i = -1;
+ while (buffer[++i] != 0) {
+ if (buffer[i] == _T_ECLIPSE('\\'))
+ buffer[i] = _T_ECLIPSE('/');
+ }
+#endif
+
+ separator = (eeLibPath != NULL) ? pathSeparator : _T_ECLIPSE('/');
+
+ if (eeLibPath != NULL) {
+ /* count number of path elements */
+ numPaths = 1;
+ c = eeLibPath;
+ while( (c = _tcschr(c, pathSeparator)) != NULL) {
+ numPaths++;
+ c++;
+ }
+ }
+
+ paths = malloc((numPaths + 1) * sizeof(_TCHAR*));
+ paths[numPaths] = NULL;
+
+ /* We are either splitting eeLibPath (eg path1:path2), or we are extracting
+ * from libPath where we want the directory containing the library and the
+ * parent directory of that */
+ for (i = 0; i < numPaths; i++) {
+ c = _tcsrchr(buffer, separator);
+ if (c != 0) {
+ *c++ = 0;
+ if (eeLibPath != NULL) {
+ path = c; /* we want from c to the end */
+ } else {
+ path = buffer; /* we want from the start to c */
+ }
+ } else {
+ if (eeLibPath != NULL) {
+ path = buffer;
+ } else {
+ paths[i] = NULL;
+ break;
+ }
+ }
+ if (path != NULL) {
+ entry = resolveSymlinks(path); /* this may be a new string */
+ paths[i] = malloc((_tcslen(entry) + 2) * sizeof(_TCHAR));
+ _stprintf( paths[i], _T_ECLIPSE("%s%c"), entry, pathSeparator );
+ if (entry != path)
+ free(entry);
+ path = NULL;
+ }
+ }
+
+ free(buffer);
+ return paths;
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
index c48f21a66..1e9b97ea5 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
@@ -102,8 +102,6 @@ static char * findLib(char * command) {
/* adjust the LD_LIBRARY_PATH for the vmLibrary */
static void adjustLibraryPath( char * vmLibrary ) {
- char * buffer;
- char * path;
char * c;
char * ldPath;
char * newPath;
@@ -120,64 +118,17 @@ static void adjustLibraryPath( char * vmLibrary ) {
fixEnvForNetscape();
#endif /* NETSCAPE_FIX */
- if (eeLibPath != NULL) {
- /*count number of path elements */
- numPaths = 1;
- c = eeLibPath;
- while( (c = strchr(c, pathSeparator)) != NULL) {
- numPaths++;
- c++;
- }
- paths = malloc(numPaths * sizeof(char*));
- path = buffer = _tcsdup(eeLibPath);
- for (i = 0; i < numPaths; i++) {
- c = strchr(path, pathSeparator);
- if(c != NULL) *c++ = 0;
- paths[i] = resolveSymlinks(path);
- length = strlen(paths[i]);
- paths[i] = realloc(paths[i], (length + 2) * sizeof(char));
- paths[i][length] = pathSeparator;
- paths[i][length + 1] = 0;
- path = c;
- }
- free(buffer);
- } else {
- numPaths = 2;
- /* we want the directory containing the library, and the parent directory of that */
- paths = malloc( numPaths * sizeof(char*));
- buffer = strdup(vmLibrary);
- for (i = 0; i < numPaths; i++) {
- c = strrchr(buffer, dirSeparator);
- *c = 0;
- paths[i] = resolveSymlinks(buffer);
- length = strlen(paths[i]);
- paths[i] = realloc(paths[i], (length + 2) * sizeof(char));
- paths[i][length] = pathSeparator;
- paths[i][length + 1] = 0;
- }
- free(buffer);
- }
+ paths = getVMLibrarySearchPath(vmLibrary);
ldPath = (char*)getenv(_T_ECLIPSE("LD_LIBRARY_PATH"));
if (!ldPath) {
ldPath = _T_ECLIPSE("");
needAdjust = 1;
} else {
- buffer = malloc((strlen(ldPath) + 2) * sizeof(char));
- sprintf(buffer, "%s%c", ldPath, pathSeparator);
- for (i = 0; i < numPaths; i++) {
- c = strstr(buffer, paths[i]);
- if ( c == NULL || !(c == buffer || *(c - 1) == pathSeparator))
- {
- /* entry not found */
- needAdjust = 1;
- break;
- }
- }
- free(buffer);
+ needAdjust = !containsPaths(ldPath, paths);
}
if (!needAdjust) {
- for (i = 0; i < numPaths; i++)
+ for (i = 0; paths[i] != NULL; i++)
free(paths[i]);
free(paths);
return;
@@ -185,19 +136,18 @@ static void adjustLibraryPath( char * vmLibrary ) {
/* set the value for LD_LIBRARY_PATH */
length = strlen(ldPath);
- if (eeLibPath != NULL) {
- newPath = malloc((length + 1 + strlen(eeLibPath) + 1) * sizeof(char));
- sprintf(newPath, "%s%c%s", eeLibPath, pathSeparator, ldPath);
- } else {
- newPath = malloc((length + 1 + strlen(paths[0]) + 1 + strlen(paths[1]) + 1) * sizeof(char));
- sprintf(newPath, "%s%c%s%c%s", paths[0], pathSeparator, paths[1], pathSeparator, ldPath);
- }
+ c = concatStrings(paths);
+ newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s"), c, ldPath);
+
setenv( "LD_LIBRARY_PATH", newPath, 1);
+ free(newPath);
+ free(c);
for (i = 0; i < numPaths; i++)
free(paths[i]);
free(paths);
-
+
/* now we must restart for this to take affect */
restartLauncher(initialArgv[0], initialArgv);
}
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
index 2bb9d2c4d..306c31199 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
@@ -36,6 +36,7 @@
#define initialArgv initialArgvW
#define secondThread secondThreadW
#define isSunVM isSunVMW
+#define getVMLibrarySearchPath getVMLibrarySearchPathW
#endif
#ifdef MACOSX
@@ -131,5 +132,8 @@ extern void processVMArgs(_TCHAR **vmargs[] );
/* is this a Sun VM, returns 0 if we don't know */
extern int isSunVM( _TCHAR * vm );
+/* an array of paths that will need to be on the search path to load the vm shared library */
+extern _TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary);
+
#endif /* ECLIPSE_OS_H */
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
index 1ed131519..645edea85 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.c
@@ -181,6 +181,50 @@ _TCHAR * checkPathList( _TCHAR* pathList, _TCHAR* programDir, int reverseOrder)
return result;
}
+_TCHAR * concatStrings(_TCHAR** strs) {
+ _TCHAR * result;
+ int i = -1, length = 0;
+ /* first count how large a buffer we need */
+ while( strs[++i] != NULL) {
+ length += _tcslen(strs[i]);
+ }
+
+ result = malloc((length + 1) * sizeof(_TCHAR));
+ result[0] = 0;
+ i = -1;
+ while(strs[++i] != NULL) {
+ result = _tcscat(result, strs[i]);
+ }
+ return result;
+}
+
+/*
+ * buffer contains a pathSeparator separated list of paths, check
+ * that it contains all the paths given. Each path is expected to be
+ * terminated with a pathSeparator character.
+ */
+int containsPaths(_TCHAR * str, _TCHAR** paths) {
+ _TCHAR * buffer;
+ _TCHAR * c;
+ int i;
+
+ /* terminate the string with a pathSeparator */
+ buffer = malloc((_tcslen(str) + 2) * sizeof(_TCHAR));
+ _stprintf(buffer, _T_ECLIPSE("%s%c"), str, pathSeparator);
+
+ for (i = 0; paths[i] != NULL; i++) {
+ c = _tcsstr(buffer, paths[i]);
+ if ( c == NULL || !(c == buffer || *(c - 1) == pathSeparator))
+ {
+ /* entry not found */
+ free(buffer);
+ return 0;
+ }
+ }
+ free(buffer);
+ return 1;
+}
+
int isVMLibrary( _TCHAR* vm )
{
_TCHAR *ch = NULL;
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
index 5be64926f..291dff428 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseUtil.h
@@ -19,6 +19,8 @@
#define checkProvidedVMType checkProvidedVMTypeW
#define checkPath checkPathW
#define checkPathList checkPathListW
+#define concatStrings concatStringsW
+#define containsPaths containsPathsW
#endif
/* constants for checkProvidedVMType */
@@ -45,6 +47,12 @@ extern _TCHAR* checkPath( _TCHAR* path, _TCHAR* programDir, int reverseOrder );
/* take a list of path separated with pathSeparator and run them through checkPath */
extern _TCHAR * checkPathList( _TCHAR* pathList, _TCHAR* programDir, int reverseOrder);
+/* take a NULL terminated array of strings and concatenate them together into one string */
+extern _TCHAR * concatStrings(_TCHAR** strs);
+
+/* check that the buffer contains all the given paths */
+extern int containsPaths(_TCHAR * str, _TCHAR** paths);
+
#ifdef AIX
/* Get the version of the VM */
extern char* getVMVersion( char* vm );
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
index 0329f4fcd..0bacee89b 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
+++ b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
@@ -169,27 +169,18 @@ _TCHAR * findVMLibrary( _TCHAR* command ) {
void adjustSearchPath( _TCHAR* vmLib ){
_TCHAR ** paths;
_TCHAR * path = NULL, *newPath = NULL;
- _TCHAR * buffer, *c;
+ _TCHAR * c;
int i, length;
int needAdjust = 0, freePath = 0;
- /* we want the directory containing the library, and the parent directory of that */
- paths = (_TCHAR**) malloc( 2 * sizeof(_TCHAR*));
- buffer = _tcsdup(vmLib);
- for (i = 0; i < 2; i++ ){
- c = _tcsrchr(buffer, dirSeparator);
- *c = 0;
- length = _tcslen(buffer);
- paths[i] = malloc((length + 2) * sizeof(_TCHAR));
- _stprintf( paths[i], _T_ECLIPSE("%s%c"), buffer, pathSeparator );
- }
- free(buffer);
+ paths = getVMLibrarySearchPath(vmLib);
/* first call to GetEnvironmentVariable tells us how big to make the buffer */
length = GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, 0);
if (length > 0) {
path = malloc(length * sizeof(_TCHAR));
GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, length);
+ needAdjust = !containsPaths(path, paths);
freePath = 1;
} else {
path = _T_ECLIPSE("");
@@ -197,31 +188,18 @@ void adjustSearchPath( _TCHAR* vmLib ){
needAdjust = 1;
}
- if(length > 0) {
- buffer = malloc((_tcslen(path) + 2) * sizeof(_TCHAR));
- _stprintf(buffer, _T_ECLIPSE("%s%c"), path, pathSeparator);
- /* check if each of our paths is already on the search path */
- for (i = 0; i < 2; i++) {
- c = _tcsstr(buffer, paths[i]);
- if ( c == NULL || !(c == buffer || *(c - 1) == pathSeparator))
- {
- /* entry not found */
- needAdjust = 1;
- break;
- }
- }
- free(buffer);
+ if (needAdjust) {
+ c = concatStrings(paths);
+ newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s"), c, path);
+ SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath);
+ free(c);
+ free(newPath);
}
-
- newPath = malloc((length + 1 + _tcslen(paths[0]) + 1 + _tcslen(paths[1]) + 1) * sizeof(_TCHAR));
- _stprintf(newPath, _T_ECLIPSE("%s%s%s"), paths[0], paths[1], path);
-
- SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath);
- for (i = 0; i < 2; i++)
+ for (i = 0; paths[i] != NULL; i++)
free(paths[i]);
free(paths);
- free(newPath);
if (freePath)
free(path);
}
@@ -246,7 +224,9 @@ static _TCHAR* findLib( _TCHAR* command ) {
/*check first to see if command already points to the library */
if (isVMLibrary(command)) {
- return command;
+ if (_tstat( command, &stats ) == 0 && (stats.st_mode & S_IFREG) != 0)
+ return command; /* exists */
+ return NULL; /* doesn't exist */
}
pathLength = location - command;
diff --git a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
index 390cb14a3..7edbecace 100644
--- a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
+++ b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
@@ -243,54 +243,33 @@ void adjustSearchPath( _TCHAR* vmLib ){
int needAdjust = 0, freePath = 0;
/* we want the directory containing the library, and the parent directory of that */
- paths = (_TCHAR**) malloc( 2 * sizeof(_TCHAR*));
- buffer = _tcsdup(vmLib);
- for (i = 0; i < 2; i++ ){
- c = _tcsrchr(buffer, dirSeparator);
- *c = 0;
- length = _tcslen(buffer);
- paths[i] = (_TCHAR*) malloc((length + 2) * sizeof(_TCHAR));
- _stprintf( paths[i], _T_ECLIPSE("%s%c"), buffer, pathSeparator );
- }
- free(buffer);
+ paths = getVMLibrarySearchPath(vmLib);
/* first call to GetEnvironmentVariable tells us how big to make the buffer */
length = GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, 0);
if (length > 0) {
path = (_TCHAR*)malloc(length * sizeof(_TCHAR));
GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, length);
+ needAdjust = containsPaths(path, paths);
freePath = 1;
} else {
path = _T_ECLIPSE("");
freePath = 0;
needAdjust = 1;
}
-
- if(length > 0) {
- buffer = (_TCHAR*)malloc((_tcslen(path) + 2) * sizeof(_TCHAR));
- _stprintf(buffer, _T_ECLIPSE("%s%c"), path, pathSeparator);
- /* check if each of our paths is already on the search path */
- for (i = 0; i < 2; i++) {
- c = _tcsstr(buffer, paths[i]);
- if ( c == NULL || !(c == buffer || *(c - 1) == pathSeparator))
- {
- /* entry not found */
- needAdjust = 1;
- break;
- }
- }
- free(buffer);
- }
-
- newPath = (_TCHAR*)malloc((length + 1 + _tcslen(paths[0]) + 1 + _tcslen(paths[1]) + 1) * sizeof(_TCHAR));
- _stprintf(newPath, _T_ECLIPSE("%s%s%s"), paths[0], paths[1], path);
- SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath);
+ if (needAdjust) {
+ c = concatStrings(paths);
+ newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s"), c, path);
+ SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath);
+ free(c);
+ free(newPath);
+ }
- for (i = 0; i < 2; i++)
+ for (i = 0; i < 2 && paths[i] != NULL; i++)
free(paths[i]);
free(paths);
- free(newPath);
if (freePath)
free(path);
}
@@ -313,7 +292,9 @@ static _TCHAR* findLib( _TCHAR* command ) {
/*check first to see if command already points to the library */
if (isVMLibrary(command)) {
- return command;
+ if (_tstat( command, &stats ) == 0 && (stats.st_mode & S_IFREG) != 0)
+ return command; /* exists */
+ return NULL; /* doesn't exist */
}
pathLength = location - command;

Back to the top