summaryrefslogtreecommitdiff
path: root/desktop/source/app/lockfile.cxx
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2003-03-25 12:52:54 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2003-03-25 12:52:54 +0000
commit568324991dbd7afa38cffeea4a16fdeeb7373f29 (patch)
tree1f982571c870c1f82e3623be6628116e6ccaf538 /desktop/source/app/lockfile.cxx
parentc8d4b39ddfd3f2e1aec22122a820fdc583b7c275 (diff)
MWS_SRX644: migrate branch mws_srx644 -> HEAD
Diffstat (limited to 'desktop/source/app/lockfile.cxx')
-rw-r--r--desktop/source/app/lockfile.cxx34
1 files changed, 30 insertions, 4 deletions
diff --git a/desktop/source/app/lockfile.cxx b/desktop/source/app/lockfile.cxx
index 847b3598ba..7e2a2f9f9d 100644
--- a/desktop/source/app/lockfile.cxx
+++ b/desktop/source/app/lockfile.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: lockfile.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: lo $ $Date: 2002-11-06 14:44:49 $
+ * last change: $Author: hr $ $Date: 2003-03-25 13:51:15 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -107,7 +107,7 @@ namespace desktop {
int tmpByte = 0;
for (int i = 0; i<nIdBytes; i++) {
tmpByte = rand( ) % 0xFF;
- sprintf( tmpId+i*2, "%02X", tmpByte );
+ sprintf( tmpId+i*2, "%02X", tmpByte ); // #100211# - checked
}
tmpId[nIdBytes*2]=0x00;
m_aId = OUString::createFromAscii( tmpId );
@@ -134,7 +134,7 @@ namespace desktop {
if (m_bIsLocked) {
// lock existed, ask user what to do
- if (execWarning( ) == RET_YES) {
+ if (isStale() || execWarning( ) == RET_YES) {
// remove file and create new
File::remove( m_aLockname );
File aFile(m_aLockname);
@@ -154,6 +154,32 @@ namespace desktop {
}
}
+ sal_Bool Lockfile::isStale( void ) const
+ {
+ // this checks whether the lockfile was created on the same
+ // host by the same user. Should this be the case it is safe
+ // to assume that it is a stale lookfile which can be overwritten
+ String aLockname = m_aLockname;
+ Config aConfig(aLockname);
+ aConfig.SetGroup(m_aGroup);
+ ByteString aHost = aConfig.ReadKey( m_aHostkey );
+ ByteString aUser = aConfig.ReadKey( m_aUserkey );
+ // lockfile from same host?
+ oslSocketResult sRes;
+ ByteString myHost = OUStringToOString(
+ SocketAddr::getLocalHostname( &sRes ), RTL_TEXTENCODING_ASCII_US );
+ if (aHost == myHost) {
+ // lockfile by same UID
+ OUString myUserName;
+ Security aSecurity;
+ aSecurity.getUserName( myUserName );
+ ByteString myUser = OUStringToOString( myUserName, RTL_TEXTENCODING_ASCII_US );
+ if (aUser == myUser)
+ return sal_True;
+ }
+ return sal_False;
+ }
+
void Lockfile::syncToFile( void ) const
{
String aLockname = m_aLockname;