1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_tools.hxx"
25 #include "sal/config.h"
26 
27 #include <stdlib.h>
28 
29 #if defined UNX
30 #include <sys/resource.h>
31 #include <sys/time.h>
32 #include <sys/types.h>
33 #endif
34 
35 #include "osl/process.h"
36 #include "osl/thread.h"
37 #include "rtl/bootstrap.hxx"
38 #include "rtl/string.hxx"
39 #include "rtl/textcvt.h"
40 #include "rtl/ustrbuf.hxx"
41 #include "rtl/ustring.h"
42 #include "rtl/ustring.hxx"
43 #include "sal/types.h"
44 #include "tools/extendapplicationenvironment.hxx"
45 
46 namespace tools {
47 
extendApplicationEnvironment()48 void extendApplicationEnvironment() {
49 #if defined UNX
50     // Try to set RLIMIT_NOFILE as large as possible (failure is harmless):
51     rlimit l;
52     if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
53         l.rlim_cur = l.rlim_max;
54         setrlimit(RLIMIT_NOFILE, &l);
55     }
56 #endif
57 
58     // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal):
59     rtl::OUStringBuffer env;
60     rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP"));
61     rtl::OUString uri;
62     if (rtl::Bootstrap::get(envVar, uri))
63     {
64         if (!uri.matchIgnoreAsciiCaseAsciiL(
65                 RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pathname:")))
66         {
67             uri = rtl::Bootstrap::encode(uri);
68         }
69         env.append(uri);
70     } else {
71         if (osl_getExecutableFile(&uri.pData) != osl_Process_E_None) {
72             abort();
73         }
74         sal_Int32 i = uri.lastIndexOf('/');
75         if (i >= 0) {
76             uri = uri.copy(0, i + 1);
77         }
78         env.append(rtl::Bootstrap::encode(uri));
79         env.appendAscii(
80             RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental")));
81     }
82     rtl::OUString envValue(env.makeStringAndClear());
83     if (osl_setEnvironment(envVar.pData, envValue.pData) != osl_Process_E_None) {
84         abort();
85     }
86 }
87 
88 }
89