@@ -64,7 +64,14 @@ static char* winPath = NULL;
64
64
/* Helper function to strip /bin/... or /lib/... from the executable path of omc */
65
65
static void stripbinpath (char * omhome )
66
66
{
67
- char * tmp ;
67
+ char * tmp = NULL ;
68
+ /* adrpo: if the path does not contain "bin" or "lib" exit gracefully as otherwise the assertion will trigger */
69
+ if (strstr (omhome , "bin" ) == NULL && strstr (omhome , "lib" ) == NULL )
70
+ {
71
+ fprintf (stderr , "could not deduce the OpenModelica installation directory from executable path: [%s], please set OPENMODELICAHOME" , omhome );
72
+ exit (EXIT_FAILURE );
73
+ }
74
+
68
75
do {
69
76
assert (tmp = strrchr (omhome ,'/' ));
70
77
* tmp = '\0' ;
@@ -86,14 +93,21 @@ const char* SettingsImpl__getInstallationDirectoryPath(void) {
86
93
const char * SettingsImpl__getInstallationDirectoryPath (void ) {
87
94
struct stat sb ;
88
95
static char omhome [PATH_MAX ];
96
+ const char * omhome_env = getenv ("OPENMODELICAHOME" );
89
97
static int init = 0 ;
90
98
ssize_t r ;
91
99
/* This is bad code using hard-coded limits; but we cannot query the size of symlinks on /proc
92
100
* because that FS is not POSIX-compliant.
93
101
*/
102
+ if (omhome_env != NULL ) {
103
+ strcpy (omhome , omhome_env );
104
+ return omhome ;
105
+ }
106
+
94
107
if (init ) {
95
108
return omhome ;
96
109
}
110
+
97
111
r = readlink ("/proc/self/exe" , omhome , sizeof (omhome )- 1 );
98
112
if (r < 0 ) {
99
113
perror ("readlink" );
@@ -113,9 +127,9 @@ const char* SettingsImpl__getInstallationDirectoryPath(void) {
113
127
const char * SettingsImpl__getInstallationDirectoryPath (void ) {
114
128
int ret ;
115
129
pid_t pid ;
116
- static char * omhome ;
130
+ static char * omhome = getenv ( "OPENMODELICAHOME" ) ;
117
131
static int init = 0 ;
118
- if (init ) {
132
+ if (init || omhome != NULL ) {
119
133
return omhome ;
120
134
}
121
135
@@ -143,11 +157,18 @@ const char* SettingsImpl__getInstallationDirectoryPath(void) {
143
157
int ret ;
144
158
pid_t pid ;
145
159
static char omhome [PROC_PIDPATHINFO_MAXSIZE ];
160
+ const char * omhome_env = getenv ("OPENMODELICAHOME" );
146
161
static int init = 0 ;
147
- if (init ) {
162
+ if (omhome_env != NULL ) {
163
+ strcpy (omhome , omhome_env );
148
164
return omhome ;
149
165
}
150
166
167
+ if (init )
168
+ {
169
+ return omhome ;
170
+ }
171
+
151
172
pid = getpid ();
152
173
ret = proc_pidpath (pid , omhome , sizeof (omhome ));
153
174
if (ret <= 0 ) {
0 commit comments