LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sal/osl/unx - salinit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 9 88.9 %
Date: 2013-07-09 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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             : #include "sal/config.h"
      21             : 
      22             : #if defined MACOSX
      23             : #include <cassert>
      24             : #include <limits>
      25             : #include <unistd.h>
      26             : #endif
      27             : 
      28             : #include "osl/process.h"
      29             : #include "sal/main.h"
      30             : #include "sal/types.h"
      31             : 
      32             : #if HAVE_SYSLOG_H
      33             : #include <string.h>
      34             : #include <syslog.h>
      35             : // from sal/osl/all/log.cxx:
      36             : extern bool sal_use_syslog;
      37             : #endif
      38             : 
      39             : extern "C" {
      40             : 
      41             : //From time.c
      42             : void sal_initGlobalTimer();
      43             : 
      44        1735 : void sal_detail_initialize(int argc, char ** argv) {
      45             : #if defined MACOSX
      46             :     // On Mac OS X, soffice can restart itself via exec (see restartOnMac in
      47             :     // desktop/source/app/app.cxx), which leaves all file descriptors open,
      48             :     // which in turn can have unwanted effects (see
      49             :     // <https://bugs.freedesktop.org/show_bug.cgi?id=50603> "Unable to update
      50             :     // LibreOffice without resetting user profile").  But closing fds in
      51             :     // restartOnMac before calling exec does not work, as additional threads
      52             :     // might still be running then, which can still use those fds and cause
      53             :     // crashes.  Therefore, the simples solution is to close fds at process
      54             :     // start (as early as possible, so that no other threads have been created
      55             :     // yet that might already have opened some fds); this is done for all kinds
      56             :     // of processes here, not just soffice, but hopefully none of our processes
      57             :     // rely on being spawned with certain fds already open.  Unfortunately, Mac
      58             :     // OS X appears to have no better interface to close all fds (like
      59             :     // closefrom):
      60             :     long openMax = sysconf(_SC_OPEN_MAX);
      61             :     if (openMax == -1) {
      62             :         // Some random value, but hopefully sysconf never returns -1 anyway:
      63             :         openMax = 1024;
      64             :     }
      65             :     assert(openMax >= 0 && openMax <= std::numeric_limits< int >::max());
      66             :     for (int fd = 3; fd < openMax; ++fd) {
      67             :         close(fd);
      68             :     }
      69             : #endif
      70        1735 :     sal_initGlobalTimer();
      71             : #if HAVE_SYSLOG_H
      72        1735 :     const char *use_syslog = getenv("SAL_LOG_SYSLOG");
      73        1735 :     sal_use_syslog = use_syslog != NULL && !strcmp(use_syslog, "1");
      74        1735 :     if (sal_use_syslog)
      75           0 :         openlog("libreoffice", 0, LOG_USER);
      76             : #endif
      77             : 
      78        1735 :     osl_setCommandArgs(argc, argv);
      79        1735 : }
      80             : 
      81        1735 : void sal_detail_deinitialize() {}
      82             : 
      83             : }
      84             : 
      85             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10