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

Generated by: LCOV version 1.10