@@ -107,8 +107,7 @@ int main ( int argc, char* argv [] )
107107 printf ( " -n Disable the usage of ncurses (For screenlog)\n " );
108108#ifndef WIN32
109109 printf ( " -x Disable simplified crash reports (To allow core dumps)\n " );
110- printf ( " -p Always add linux-libs directory to library search path\n " );
111- printf ( " -q Never add linux-libs directory to library search path\n " );
110+ printf ( " -q Do not add " LINUX_LIBS_PATH " directory to library search path\n " );
112111#endif
113112 printf ( " -D [PATH] Use as base directory\n " );
114113 printf ( " --config [FILE] Alternate mtaserver.conf file\n " );
@@ -186,70 +185,50 @@ int main ( int argc, char* argv [] )
186185
187186#ifndef WIN32
188187//
189- // Add linux-libs to library search path if either :
188+ // Add linux-libs to library search path if:
190189// 1. Options don't forbid it (-q)
191- // 2. Options force it (-p)
192- // 3. net.so is not loadable
190+ // 2. linux-libs is not already in the library search path
193191//
194192void HandleLinuxLibs ( const SString& strLaunchDirectory, int argc, char * argv [] )
195193{
196- // Check linux-libs options
197- bool bUseLinuxLibs = false ;
198- bool bForbidLinuxLibs = false ;
194+ // Check for linux-libs forbidden option
199195 for ( int i = 1 ; i < argc ; i++ )
200196 {
201- bUseLinuxLibs |= ( strcmp ( argv[i], " -p " ) == 0 );
202- bForbidLinuxLibs |= ( strcmp ( argv[i], " -q " ) == 0 ) ;
197+ if ( strcmp ( argv[i], " -q " ) == 0 )
198+ return ;
203199 }
204200
205- // Is linux-libs forbidden by options?
206- if ( bForbidLinuxLibs )
207- return ;
208-
209201 // Calculate absolute path to MTA directory
210202 SString strSavedDir = GetSystemCurrentDirectory ();
211203 chdir ( strLaunchDirectory );
212204 SString strAbsLaunchDirectory = GetSystemCurrentDirectory ();
213205 chdir ( strSavedDir );
214206
215- if ( !bUseLinuxLibs )
216- {
217- // linux-libs not forced by options - Check if net module might need it
218- void * hModule = dlopen ( strAbsLaunchDirectory + " /" LIB_NET, RTLD_NOW );
219- if ( hModule )
220- dlclose ( hModule );
221- else
222- bUseLinuxLibs = true ;
223- }
207+ SString strLdLibraryPath = getenv ( " LD_LIBRARY_PATH" );
208+ SString strLinuxLibsPath = strAbsLaunchDirectory + " /" LINUX_LIBS_PATH;
224209
225- if ( bUseLinuxLibs )
210+ // Check that linux-libs is not already in library path
211+ if ( !strLdLibraryPath.Contains ( strLinuxLibsPath ) )
226212 {
227- SString strLdLibraryPath = getenv ( " LD_LIBRARY_PATH" );
228- SString strLinuxLibsPath = strAbsLaunchDirectory + " /" LINUX_LIBS_PATH;
229-
230- // Check that linux-libs is not already in library path
231- if ( !strLdLibraryPath.Contains ( strLinuxLibsPath ) )
213+ // Add linux-libs to search path
214+ if ( !strLdLibraryPath.empty () )
215+ strLdLibraryPath += " ;" ;
216+ strLdLibraryPath += strLinuxLibsPath;
217+ SString strEnvString = SStringX ( " LD_LIBRARY_PATH=" ) + strLdLibraryPath;
218+ putenv ( (char *)*strEnvString );
219+
220+ // Add -q to ensure linux-libs don't get added again
221+ char ** pArgArray = new char *[argc + 2 ];
222+ for ( int i = 0 ; i <= argc ; i++ )
232223 {
233- // Add linux-libs to search path
234- if ( !strLdLibraryPath.empty () )
235- strLdLibraryPath += " ;" ;
236- strLdLibraryPath += strLinuxLibsPath;
237- SString strEnvString = SStringX ( " LD_LIBRARY_PATH=" ) + strLdLibraryPath;
238- putenv ( (char *)*strEnvString );
239-
240- // Add -q to ensure linux-libs don't get added again
241- char ** pArgArray = new char *[argc + 2 ];
242- for ( int i = 0 ; i <= argc ; i++ )
243- {
244- pArgArray[i] = argv[i];
245- }
246- char newArg[] = " -q" ;
247- pArgArray[argc] = newArg;
248- pArgArray[argc + 1 ] = nullptr ;
249-
250- // Go for launch #2
251- execv ( argv[0 ], pArgArray );
224+ pArgArray[i] = argv[i];
252225 }
226+ char newArg[] = " -q" ;
227+ pArgArray[argc] = newArg;
228+ pArgArray[argc + 1 ] = nullptr ;
229+
230+ // Go for launch #2
231+ execv ( argv[0 ], pArgArray );
253232 }
254233}
255234#endif
0 commit comments