diff options
author | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | 2013-03-23 13:32:26 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-04-03 09:52:39 +0000 |
commit | b267ee91d24ee093a40325300c10d12f3e8d023b (patch) | |
tree | ec68486deec4e9bc1797d70c1a6b81711a1b7770 /desktop | |
parent | 12b08780473d721e3ab12fa2909b24dc9c635a8b (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')
-rw-r--r-- | desktop/source/app/app.cxx | 58 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.cxx | 9 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.hxx | 2 | ||||
-rw-r--r-- | desktop/source/app/cmdlinehelp.cxx | 2 |
4 files changed, 71 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(); diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index aded2492b5e4..061bd0ea79b5 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 a9c2c482bdcf..4ea5e0dbd4c7 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 0680804a1e08..e40dcd099238 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); |