Kaydet (Commit) b267ee91 authored tarafından Riccardo Magliocchetti's avatar Riccardo Magliocchetti Kaydeden (comit) Thorsten Behrens

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/2928Reviewed-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
Reviewed-by: 's avatarThorsten Behrens <tbehrens@suse.com>
Tested-by: 's avatarThorsten Behrens <tbehrens@suse.com>
üst 12b08780
......@@ -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();
......
......@@ -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: */
......@@ -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;
};
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment