xref: /core/desktop/scripts/soffice.sh (revision 35463d88)
1#!/bin/sh
2#
3# This file is part of the LibreOffice project.
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8#
9# This file incorporates work covered by the following license notice:
10#
11#   Licensed to the Apache Software Foundation (ASF) under one or more
12#   contributor license agreements. See the NOTICE file distributed
13#   with this work for additional information regarding copyright
14#   ownership. The ASF licenses this file to you under the Apache
15#   License, Version 2.0 (the "License"); you may not use this file
16#   except in compliance with the License. You may obtain a copy of
17#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18#
19
20# use POSIX locale for well-defined tool output
21LO_SAVE_LC_ALL="$LC_ALL"
22LC_ALL=C
23export LC_ALL
24
25#
26# STAR_PROFILE_LOCKING_DISABLED=1
27# export STAR_PROFILE_LOCKING_DISABLED
28#
29
30# file locking now enabled by default
31SAL_ENABLE_FILE_LOCKING=1
32export SAL_ENABLE_FILE_LOCKING
33
34# uncomment line below to disable anti aliasing of fonts
35# SAL_ANTIALIAS_DISABLE=true; export SAL_ANTIALIAS_DISABLE
36
37# uncomment line below if you encounter problems starting soffice on your system
38# SAL_NO_XINITTHREADS=true; export SAL_NO_XINITTHREADS
39
40#@JITC_PROCESSOR_TYPE_EXPORT@
41
42# resolve installation directory
43sd_cwd=$(pwd)
44sd_res="$0"
45while [ -h "$sd_res" ] ; do
46    sd_dirname=$(dirname "$sd_res")
47    cd "$sd_dirname" || exit $?
48    sd_basename=$(basename "$sd_res")
49    sd_res=$(ls -l "$sd_basename" | sed "s/.*$sd_basename -> //g")
50done
51sd_dirname=$(dirname "$sd_res")
52cd "$sd_dirname" || exit $?
53sd_prog=$(pwd)
54cd "$sd_cwd" || exit $?
55
56# linked build needs additional settings
57if [ -e "${sd_prog}/ooenv" ] ; then
58    # shellcheck source=../../instsetoo_native/ooenv
59    . "${sd_prog}/ooenv"
60fi
61
62# try to get some debug output?
63GDBTRACECHECK=
64STRACECHECK=
65VALGRINDCHECK=
66RRCHECK=
67
68# count number of selected checks; only one is allowed
69checks=
70EXTRAOPT=
71# force the --valgrind option if the VALGRIND variable is set
72test -n "$VALGRIND" && EXTRAOPT="--valgrind"
73
74# force the --record option if the RR variable is set
75test -n "$RR" && EXTRAOPT="--record"
76
77for arg in "$@" $EXTRAOPT ; do
78    case "$arg" in
79        --record)
80            if which rr >/dev/null 2>&1 ; then
81                # smoketest may already be recorded => use ignore-nested
82                RRCHECK="rr record --ignore-nested"
83                checks="c$checks"
84            else
85                echo "Error: Can't find the tool \"rr\", --record option will be ignored."
86                exit 1
87            fi
88            ;;
89        --backtrace)
90            if which gdb >/dev/null 2>&1 ; then
91                GDBTRACECHECK="gdb -nx --command=$sd_prog/gdbtrace --args"
92                checks="c$checks"
93            else
94                echo "Error: Can't find the tool \"gdb\", --backtrace option will be ignored."
95                exit 1
96            fi
97            ;;
98        --strace)
99            if which strace >/dev/null 2>&1 ; then
100                STRACECHECK="strace -o strace.log -f -tt -s 256"
101                checks="c$checks"
102            else
103                echo "Error: Can't find the tool \"strace\", --strace option will be ignored."
104                exit 1;
105            fi
106            ;;
107         --valgrind)
108            test -n "$VALGRINDCHECK" && continue;
109            if which valgrind >/dev/null 2>&1 ; then
110                # another valgrind tool might be forced via the environment variable
111                test -z "$VALGRIND" && VALGRIND="memcheck"
112                # --trace-children-skip is pretty useful but supported only with valgrind >= 3.6.0
113                valgrind_ver=$(valgrind --version | sed -e "s/valgrind-//")
114                valgrind_ver_maj=$(echo "$valgrind_ver" | awk -F. '{ print $1 }')
115                valgrind_ver_min=$(echo "$valgrind_ver" | awk -F. '{ print $2 }')
116                valgrind_skip=
117                if [ "$valgrind_ver_maj" -gt 3 ] || ( [ "$valgrind_ver_maj" -eq 3 ] && [ "$valgrind_ver_min" -ge 6 ] ) ; then
118                    valgrind_skip='--trace-children-skip=*/java,*/gij'
119                fi
120                # finally set the valgrind check
121                VALGRINDCHECK="valgrind --tool=$VALGRIND --trace-children=yes $valgrind_skip --num-callers=50 --error-limit=no"
122                echo "use kill -SIGUSR2 pid to dump traces of active allocations"
123                checks="c$checks"
124                case "$VALGRIND" in
125                helgrind|memcheck|massif|exp-dhat)
126                    export G_SLICE=always-malloc
127                    export GLIBCXX_FORCE_NEW=1
128                    ;;
129                callgrind)
130                    unset MALLOC_CHECK_ MALLOC_PERTURB_ G_SLICE
131                    export SAL_DISABLE_FLOATGRAB=1
132                    export OOO_DISABLE_RECOVERY=1
133                    export SAL_DISABLE_GL_WATCHDOG=1
134                    export LD_BIND_NOW=1
135                    ;;
136                esac
137            else
138                echo "Error: Can't find the tool \"valgrind\", --valgrind option will be ignored"
139                exit 1
140            fi
141            ;;
142    esac
143done
144
145if echo "$checks" | grep -q "cc" ; then
146    echo "Error: The debug options --record, --backtrace, --strace, and --valgrind cannot be used together."
147    echo "       Please, use them one by one."
148    exit 1;
149fi
150
151case "$(uname -s)" in
152OpenBSD)
153# this is a temporary hack until we can live with the default search paths
154    LD_LIBRARY_PATH="$sd_prog${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
155    JAVA_HOME=$(javaPathHelper -h libreoffice-java 2> /dev/null)
156    export LD_LIBRARY_PATH
157    if [ -n "${JAVA_HOME}" ]; then
158        export JAVA_HOME
159    fi
160    ;;
161NetBSD|DragonFly)
162# this is a temporary hack until we can live with the default search paths
163    LD_LIBRARY_PATH="$sd_prog${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
164    export LD_LIBRARY_PATH
165    ;;
166AIX)
167    LIBPATH="$sd_prog${LIBPATH:+:$LIBPATH}"
168    export LIBPATH
169    ;;
170esac
171
172# restore locale setting
173LC_ALL="$LO_SAVE_LC_ALL"
174
175# run soffice.bin directly when you want to get the backtrace
176if [ -n "$GDBTRACECHECK" ] ; then
177    exec $GDBTRACECHECK "$sd_prog/soffice.bin" "$@"
178fi
179
180# valgrind --log-file=valgrind.log does not work well with --trace-children=yes
181if [ -n "$VALGRINDCHECK" ] && [ -z "$VALGRIND" ] ; then
182    echo "redirecting the standard and the error output to valgrind.log"
183    exec > valgrind.log 2>&1
184fi
185
186# oosplash does the rest: forcing pages in, javaldx etc. are
187exec $RRCHECK $VALGRINDCHECK $STRACECHECK "$sd_prog/oosplash" "$@"
188