[Libreoffice-commits] .: Branch 'libreoffice-3-5-5' - sal/osl

Michael Meeks michael at kemper.freedesktop.org
Tue Jun 19 05:55:57 PDT 2012


 sal/osl/unx/salinit.cxx |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

New commits:
commit a76695e1f3e0ad3a6a610ed7ffe6cd0507bde4aa
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Jun 18 13:00:08 2012 +0200

    fdo#50603: Close fds across a restart of soffice on Mac OS X
    
    ...where the restart is directly from the old soffice instance, via exec, so the
    restarted soffice would inherit all open fds from the old one.  The easiest
    approach appears to close fds upon startup.
    
    Change-Id: I89bb1c78f3adf2da1cd3cbd58c22df276133a883
    Signed-off-by: Andras Timar <atimar at suse.com>
    Signed-off-by: Caolan McNamara <caolanm at redhat.com>
    Signed-off-by: Michael Meeks <michael.meeks at suse.com>

diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index 81b1c1c..102ebe0 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -28,12 +28,44 @@
 
 #include "sal/config.h"
 
+#if defined MACOSX
+#include <cassert>
+#include <limits>
+#include <unistd.h>
+#endif
+
 #include "osl/process.h"
 #include "sal/types.h"
 
 extern "C" {
 
 void SAL_CALL sal_detail_initialize(int argc, char ** argv) {
+#if defined MACOSX
+    // On Mac OS X, soffice can restart itself via exec (see restartOnMac in
+    // desktop/source/app/app.cxx), which leaves all file descriptors open,
+    // which in turn can have unwanted effects (see
+    // <https://bugs.freedesktop.org/show_bug.cgi?id=50603> "Unable to update
+    // LibreOffice without resetting user profile").  But closing fds in
+    // restartOnMac before calling exec does not work, as additional threads
+    // might still be running then, wich can still use those fds and cause
+    // crashes.  Therefore, the simples solution is to close fds at process
+    // start (as early as possible, so that no other threads have been created
+    // yet that might already have opened some fds); this is done for all kinds
+    // of processes here, not just soffice, but hopefully none of our processes
+    // rely on being spawned with certain fds already open.  Unfortunately, Mac
+    // OS X appears to have no better interface to close all fds (like
+    // closefrom):
+    long openMax = sysconf(_SC_OPEN_MAX);
+    if (openMax == -1) {
+        // Some random value, but hopefully sysconf never returns -1 anyway:
+        openMax = 1024;
+    }
+    assert(openMax >= 0 && openMax <= std::numeric_limits< int >::max());
+    for (int fd = 3; fd < openMax; ++fd) {
+        close(fd);
+    }
+#endif
+
     osl_setCommandArgs(argc, argv);
 }
 


More information about the Libreoffice-commits mailing list