[Libreoffice-commits] core.git: desktop/source

Riccardo Magliocchetti riccardo.magliocchetti at gmail.com
Wed Apr 3 02:53:00 PDT 2013


 desktop/source/app/app.cxx         |   58 +++++++++++++++++++++++++++++++++++++
 desktop/source/app/cmdlineargs.cxx |    9 +++++
 desktop/source/app/cmdlineargs.hxx |    2 +
 desktop/source/app/cmdlinehelp.cxx |    2 +
 4 files changed, 71 insertions(+)

New commits:
commit b267ee91d24ee093a40325300c10d12f3e8d023b
Author: Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>
Date:   Sat Mar 23 13:32:26 2013 +0100

    desktop: add --pidfile switch
    
    Store the soffice.bin pid to a file. Useful with --headless where
    you may have libreoffice supervised by another process.
    
    Change-Id: I6a3c6cb920fc7b8e659a01975b4d457ce5525b17
    Reviewed-on: https://gerrit.libreoffice.org/2928
    Reviewed-by: Chris Sherlock <chris.sherlock79 at gmail.com>
    Reviewed-by: Thorsten Behrens <tbehrens at suse.com>
    Tested-by: Thorsten Behrens <tbehrens at suse.com>

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 3eb4ab1..32c8b55 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -126,6 +126,14 @@
 #endif
 #endif //WNT
 
+#if defined WNT
+#include <process.h>
+#define GETPID _getpid
+#else
+#include <unistd.h>
+#define GETPID getpid
+#endif
+
 using namespace ::com::sun::star::awt;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::util;
@@ -1572,6 +1580,38 @@ int Desktop::Main()
         impl_checkRecoveryState(bCrashed, bExistsRecoveryData, bExistsSessionData);
         RTL_LOGFILE_CONTEXT_TRACE( aLog, "} impl_checkRecoveryState" );
 
+        OUString pidfileName = rCmdLineArgs.GetPidfileName();
+        if ( !pidfileName.isEmpty() )
+        {
+            OUString pidfileURL;
+
+            if ( osl_getFileURLFromSystemPath(pidfileName.pData, &pidfileURL.pData) == osl_File_E_None )
+            {
+                osl::File pidfile( pidfileURL );
+                osl::FileBase::RC rc;
+
+                osl::File::remove( pidfileURL );
+                if ( (rc = pidfile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) ) == osl::File::E_None )
+                {
+                    OString pid( OString::valueOf( static_cast<sal_Int32>( GETPID() ) ) );
+                    sal_uInt64 written = 0;
+                    if ( pidfile.write(pid.getStr(), pid.getLength(), written) != osl::File::E_None )
+                    {
+                        SAL_WARN("desktop", "cannot write pidfile " << pidfile.getURL());
+                    }
+                    pidfile.close();
+                }
+                else
+                {
+                    SAL_WARN("desktop", "cannot open pidfile " << pidfile.getURL() << osl::FileBase::RC(rc));
+                }
+            }
+            else
+            {
+                SAL_WARN("desktop", "cannot get pidfile URL from path" << pidfileName);
+            }
+        }
+
         if ( rCmdLineArgs.IsHeadless() )
         {
             // Ensure that we use not the system file dialogs as
@@ -1741,6 +1781,24 @@ int Desktop::doShutdown()
     if ( rCmdLineArgs.IsHeadless() )
         SvtMiscOptions().SetUseSystemFileDialog( pExecGlobals->bUseSystemFileDialog );
 
+    OUString pidfileName = rCmdLineArgs.GetPidfileName();
+    if ( !pidfileName.isEmpty() )
+    {
+        OUString pidfileURL;
+
+        if ( osl_getFileURLFromSystemPath(pidfileName.pData, &pidfileURL.pData) == osl_File_E_None )
+        {
+            if ( osl::File::remove( pidfileURL ) != osl::FileBase::E_None )
+            {
+                SAL_WARN("desktop", "shutdown: cannot remove pidfile " << pidfileURL);
+            }
+        }
+        else
+        {
+            SAL_WARN("desktop", "shutdown: cannot get pidfile URL from path" << pidfileName);
+        }
+    }
+
     // remove temp directory
     RemoveTemporaryDirectory();
     FlushConfiguration();
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx
index aded249..061bd0e 100644
--- a/desktop/source/app/cmdlineargs.cxx
+++ b/desktop/source/app/cmdlineargs.cxx
@@ -529,6 +529,10 @@ bool CommandLineArgs::InterpretCommandLineParameter( const ::rtl::OUString& aArg
     {
         m_language = oArg.copy(RTL_CONSTASCII_LENGTH("language="));
     }
+    else if ( oArg.matchIgnoreAsciiCase("pidfile="))
+    {
+        m_pidfile = oArg.copy(RTL_CONSTASCII_LENGTH("pidfile="));
+    }
     else if ( oArg == "writer" )
     {
         m_writer = true;
@@ -853,6 +857,11 @@ bool CommandLineArgs::WantsToLoadDocument() const
     return m_bDocumentArgs;
 }
 
+OUString CommandLineArgs::GetPidfileName() const
+{
+    return m_pidfile;
+}
+
 } // namespace desktop
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx
index a9c2c48..4ea5e0d 100644
--- a/desktop/source/app/cmdlineargs.hxx
+++ b/desktop/source/app/cmdlineargs.hxx
@@ -105,6 +105,7 @@ class CommandLineArgs: private boost::noncopyable
         std::vector< rtl::OUString > GetConversionList() const;
         rtl::OUString       GetConversionParams() const;
         rtl::OUString       GetConversionOut() const;
+        OUString       GetPidfileName() const;
 
         // Special analyzed states (does not match directly to a command line parameter!)
         bool IsEmpty() const;
@@ -166,6 +167,7 @@ class CommandLineArgs: private boost::noncopyable
         rtl::OUString m_conversionout; // contains external URIs
         std::vector< rtl::OUString > m_infilter;
         rtl::OUString m_language;
+        OUString m_pidfile;
 };
 
 }
diff --git a/desktop/source/app/cmdlinehelp.cxx b/desktop/source/app/cmdlinehelp.cxx
index 0680804..e40dcd0 100644
--- a/desktop/source/app/cmdlinehelp.cxx
+++ b/desktop/source/app/cmdlinehelp.cxx
@@ -123,6 +123,8 @@ namespace desktop
         "      If --outdir is not specified then current working dir is used as output_dir.\n"\
         "      Eg. --print-to-file *.doc\n"\
         "          --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc\n"\
+        "--pidfile file\n"\
+        "      Store soffice.bin pid to file.\n"\
         "\nRemaining arguments will be treated as filenames or URLs of documents to open.\n\n";
 
     rtl::OUString ReplaceStringHookProc(const rtl::OUString& rStr);


More information about the Libreoffice-commits mailing list