1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_tools.hxx" 29 #include "sal/config.h" 30 31 #include <stdlib.h> 32 33 #if defined UNX 34 #include <sys/resource.h> 35 #include <sys/time.h> 36 #include <sys/types.h> 37 #endif 38 39 #include "osl/process.h" 40 #include "osl/thread.h" 41 #include "rtl/bootstrap.hxx" 42 #include "rtl/string.hxx" 43 #include "rtl/textcvt.h" 44 #include "rtl/ustrbuf.hxx" 45 #include "rtl/ustring.h" 46 #include "rtl/ustring.hxx" 47 #include "sal/types.h" 48 #include "tools/extendapplicationenvironment.hxx" 49 50 namespace tools { 51 52 void extendApplicationEnvironment() { 53 #if defined UNX 54 // Try to set RLIMIT_NOFILE as large as possible (failure is harmless): 55 rlimit l; 56 if (getrlimit(RLIMIT_NOFILE, &l) == 0) { 57 l.rlim_cur = l.rlim_max; 58 setrlimit(RLIMIT_NOFILE, &l); 59 } 60 #endif 61 62 // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal): 63 rtl::OUStringBuffer env; 64 rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")); 65 rtl::OUString uri; 66 if (rtl::Bootstrap::get(envVar, uri)) 67 { 68 if (!uri.matchIgnoreAsciiCaseAsciiL( 69 RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pathname:"))) 70 { 71 uri = rtl::Bootstrap::encode(uri); 72 } 73 env.append(uri); 74 } else { 75 if (osl_getExecutableFile(&uri.pData) != osl_Process_E_None) { 76 abort(); 77 } 78 sal_Int32 i = uri.lastIndexOf('/'); 79 if (i >= 0) { 80 uri = uri.copy(0, i + 1); 81 } 82 env.append(rtl::Bootstrap::encode(uri)); 83 env.appendAscii( 84 RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental"))); 85 } 86 rtl::OUString envValue(env.makeStringAndClear()); 87 if (osl_setEnvironment(envVar.pData, envValue.pData) != osl_Process_E_None) { 88 abort(); 89 } 90 } 91 92 } 93