[PATCH] desktop: add --pidfile switch

Riccardo Magliocchetti (via Code Review) gerrit at gerrit.libreoffice.org
Sat Mar 23 05:42:14 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2928

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/28/2928/1

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
---
M desktop/source/app/app.cxx
M desktop/source/app/cmdlineargs.cxx
M desktop/source/app/cmdlineargs.hxx
M desktop/source/app/cmdlinehelp.cxx
4 files changed, 71 insertions(+), 0 deletions(-)



diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index d3e7b26..aef2d1f 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -124,6 +124,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;
@@ -1570,6 +1578,38 @@
         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
@@ -1739,6 +1779,24 @@
     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 83a251c..24de22a 100644
--- a/desktop/source/app/cmdlineargs.cxx
+++ b/desktop/source/app/cmdlineargs.cxx
@@ -525,6 +525,10 @@
     {
         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;
@@ -849,6 +853,11 @@
     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 @@
         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 @@
         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 @@
         "      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);

-- 
To view, visit https://gerrit.libreoffice.org/2928
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6a3c6cb920fc7b8e659a01975b4d457ce5525b17
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>



More information about the LibreOffice mailing list