summaryrefslogtreecommitdiff
path: root/desktop/source/app/app.cxx
diff options
context:
space:
mode:
authorRiccardo Magliocchetti <riccardo.magliocchetti@gmail.com>2013-03-23 13:32:26 +0100
committerThorsten Behrens <tbehrens@suse.com>2013-04-03 09:52:39 +0000
commitb267ee91d24ee093a40325300c10d12f3e8d023b (patch)
treeec68486deec4e9bc1797d70c1a6b81711a1b7770 /desktop/source/app/app.cxx
parent12b08780473d721e3ab12fa2909b24dc9c635a8b (diff)
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@gmail.com> Reviewed-by: Thorsten Behrens <tbehrens@suse.com> Tested-by: Thorsten Behrens <tbehrens@suse.com>
Diffstat (limited to 'desktop/source/app/app.cxx')
-rw-r--r--desktop/source/app/app.cxx58
1 files changed, 58 insertions, 0 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 3eb4ab10305b..32c8b558caca 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();