[Libreoffice-commits] .: 2 commits - desktop/source

Jan Holesovsky kendy at kemper.freedesktop.org
Fri Oct 15 02:43:03 PDT 2010


 desktop/source/app/lockfile.cxx  |  112 ++++++++++++++++-----------------------
 desktop/source/app/lockfile.hxx  |   17 ++---
 desktop/source/app/lockfile2.cxx |   10 +--
 3 files changed, 60 insertions(+), 79 deletions(-)

New commits:
commit 323b43883090b53de11123097a818c77aeb5098e
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Fri Oct 15 11:38:35 2010 +0200

    Don't expose unnecessary symbols in lockfile.
    
    lockfile-less-symbols.diff

diff --git a/desktop/source/app/lockfile.cxx b/desktop/source/app/lockfile.cxx
index 514aa65..db23c7d 100644
--- a/desktop/source/app/lockfile.cxx
+++ b/desktop/source/app/lockfile.cxx
@@ -86,24 +86,6 @@ static rtl::OString impl_getHostname()
 
 namespace desktop {
 
-    // initialize static members...
-    // lock suffix
-    const OUString Lockfile::Suffix()
-        { return OUString::createFromAscii( "/.lock" ); }
-    // values for datafile
-    const ByteString Lockfile::Group()
-        { return ByteString( "Lockdata" ); }
-    const ByteString Lockfile::Userkey()
-        { return ByteString( "User" ); }
-    const ByteString Lockfile::Hostkey()
-        { return ByteString( "Host" ); }
-    const ByteString Lockfile::Stampkey()
-        { return ByteString( "Stamp" ); }
-    const ByteString Lockfile::Timekey()
-        { return ByteString( "Time" ); }
-    const ByteString Lockfile::IPCkey()
-        { return ByteString( "IPCServer" ); }
-
     Lockfile::Lockfile( bool bIPCserver )
     :m_bIPCserver(bIPCserver)
     ,m_bRemove(sal_False)
@@ -112,7 +94,7 @@ namespace desktop {
         // build the file-url to use for the lock
         OUString aUserPath;
         utl::Bootstrap::locateUserInstallation( aUserPath );
-        m_aLockname = aUserPath + Suffix();
+        m_aLockname = aUserPath + LOCKFILE_SUFFIX;
 
         // generate ID
         const int nIdBytes = 16;
@@ -182,13 +164,13 @@ namespace desktop {
         // to assume that it is a stale lockfile which can be overwritten
         String aLockname = m_aLockname;
         Config aConfig(aLockname);
-        aConfig.SetGroup(Group());
-        ByteString aIPCserver  = aConfig.ReadKey( IPCkey() );
+        aConfig.SetGroup(LOCKFILE_GROUP);
+        ByteString aIPCserver  = aConfig.ReadKey( LOCKFILE_IPCKEY );
         if (! aIPCserver.EqualsIgnoreCaseAscii( "true" ))
             return false;
 
-        ByteString aHost  = aConfig.ReadKey( Hostkey() );
-        ByteString aUser  = aConfig.ReadKey( Userkey() );
+        ByteString aHost  = aConfig.ReadKey( LOCKFILE_HOSTKEY );
+        ByteString aUser  = aConfig.ReadKey( LOCKFILE_USERKEY );
 
         // lockfile from same host?
         ByteString myHost( impl_getHostname() );
@@ -208,7 +190,7 @@ namespace desktop {
     {
         String aLockname = m_aLockname;
         Config aConfig(aLockname);
-        aConfig.SetGroup(Group());
+        aConfig.SetGroup(LOCKFILE_GROUP);
 
         // get information
         ByteString aHost( impl_getHostname() );
@@ -220,12 +202,12 @@ namespace desktop {
         ByteString aStamp = OUStringToOString( m_aId, RTL_TEXTENCODING_ASCII_US );
 
         // write information
-        aConfig.WriteKey( Userkey(),  aUser );
-        aConfig.WriteKey( Hostkey(),  aHost );
-        aConfig.WriteKey( Stampkey(), aStamp );
-        aConfig.WriteKey( Timekey(),  aTime );
+        aConfig.WriteKey( LOCKFILE_USERKEY,  aUser );
+        aConfig.WriteKey( LOCKFILE_HOSTKEY,  aHost );
+        aConfig.WriteKey( LOCKFILE_STAMPKEY, aStamp );
+        aConfig.WriteKey( LOCKFILE_TIMEKEY,  aTime );
         aConfig.WriteKey(
-            IPCkey(),
+            LOCKFILE_IPCKEY,
             m_bIPCserver ? ByteString("true") : ByteString("false") );
         aConfig.Flush( );
     }
diff --git a/desktop/source/app/lockfile.hxx b/desktop/source/app/lockfile.hxx
index ad971ca..3e2761f 100644
--- a/desktop/source/app/lockfile.hxx
+++ b/desktop/source/app/lockfile.hxx
@@ -45,6 +45,14 @@
 
 class ByteString;
 
+#define LOCKFILE_SUFFIX   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/.lock" ) )
+#define LOCKFILE_GROUP    ByteString( "Lockdata" )
+#define LOCKFILE_USERKEY  ByteString( "User" )
+#define LOCKFILE_HOSTKEY  ByteString( "Host" )
+#define LOCKFILE_STAMPKEY ByteString( "Stamp" )
+#define LOCKFILE_TIMEKEY  ByteString( "Time" )
+#define LOCKFILE_IPCKEY   ByteString( "IPCServer" )
+
 namespace desktop {
 
     class Lockfile;
@@ -71,15 +79,6 @@ namespace desktop {
         ~Lockfile(void);
 
     private:
-        // data in lockfile
-        static const ByteString Group();
-        static const ByteString Userkey();
-        static const ByteString Hostkey();
-        static const ByteString Stampkey();
-        static const ByteString Timekey();
-        static const ByteString IPCkey();
-        // lockfilename
-        static const rtl::OUString Suffix();
         bool m_bIPCserver;
         // full qualified name (file://-url) of the lockfile
         rtl::OUString m_aLockname;
diff --git a/desktop/source/app/lockfile2.cxx b/desktop/source/app/lockfile2.cxx
index c932fb2..9f61c56 100644
--- a/desktop/source/app/lockfile2.cxx
+++ b/desktop/source/app/lockfile2.cxx
@@ -43,11 +43,11 @@ bool Lockfile_execWarning( Lockfile * that )
     // read information from lock
     String aLockname = that->m_aLockname;
     Config aConfig(aLockname);
-    aConfig.SetGroup(that->Group());
-    ByteString aHost  = aConfig.ReadKey( that->Hostkey() );
-    ByteString aUser  = aConfig.ReadKey( that->Userkey() );
-    ByteString aStamp = aConfig.ReadKey( that->Stampkey() );
-    ByteString aTime  = aConfig.ReadKey( that->Timekey() );
+    aConfig.SetGroup( LOCKFILE_GROUP );
+    ByteString aHost  = aConfig.ReadKey( LOCKFILE_HOSTKEY );
+    ByteString aUser  = aConfig.ReadKey( LOCKFILE_USERKEY );
+    ByteString aStamp = aConfig.ReadKey( LOCKFILE_STAMPKEY );
+    ByteString aTime  = aConfig.ReadKey( LOCKFILE_TIMEKEY );
     
     // display warning and return response
     QueryBox aBox( NULL, DesktopResId( QBX_USERDATALOCKED ) );
commit e739fe0869ed4bb26615def73d83e055145148e8
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Fri Oct 15 11:37:46 2010 +0200

    Don't do dns lookup on startup.
    
    lockfile-dont-do-dns-lookup.diff, n#389257

diff --git a/desktop/source/app/lockfile.cxx b/desktop/source/app/lockfile.cxx
index 7803074..514aa65 100644
--- a/desktop/source/app/lockfile.cxx
+++ b/desktop/source/app/lockfile.cxx
@@ -34,6 +34,8 @@
 #include <tools/prewin.h>
 #include <windows.h>
 #include <tools/postwin.h>
+#else
+#include <unistd.h>
 #endif
 #include <sal/types.h>
 #include <osl/file.hxx>
@@ -51,6 +53,37 @@ using namespace ::rtl;
 using namespace ::utl;
 
 
+static rtl::OString impl_getHostname()
+{
+    rtl::OString aHost;
+#ifdef WNT
+    /*
+       prevent windows from connecting to the net to get it's own
+       hostname by using the netbios name
+       */
+    sal_Int32 sz = MAX_COMPUTERNAME_LENGTH + 1;
+    char* szHost = new char[sz];
+    if (GetComputerName(szHost, (LPDWORD)&sz))
+        aHost = OString(szHost);
+    else
+        aHost = OString("UNKNOWN");
+    delete[] szHost;
+#else
+    /* Don't do dns lookup on Linux either */
+    sal_Char pHostName[1024];
+
+    if ( gethostname( pHostName, sizeof( pHostName ) - 1 ) == 0 )
+    {
+        pHostName[sizeof( pHostName ) - 1] = '\0';
+        aHost = OString( pHostName );
+    }
+    else
+        aHost = OString("UNKNOWN");
+#endif
+
+    return aHost;
+}
+
 namespace desktop {
 
     // initialize static members...
@@ -156,25 +189,9 @@ namespace desktop {
 
         ByteString aHost  = aConfig.ReadKey( Hostkey() );
         ByteString aUser  = aConfig.ReadKey( Userkey() );
+
         // lockfile from same host?
-        ByteString myHost;
-#ifdef WNT
-        /*
-          prevent windows from connecting to the net to get it's own
-          hostname by using the netbios name
-        */
-        sal_Int32 sz = MAX_COMPUTERNAME_LENGTH + 1;
-        char* szHost = new char[sz];
-        if (GetComputerName(szHost, (LPDWORD)&sz))
-            myHost = OString(szHost);
-        else
-            myHost = OString("UNKNOWN");
-        delete[] szHost;
-#else
-        oslSocketResult sRes;
-        myHost  = OUStringToOString(
-            SocketAddr::getLocalHostname( &sRes ), RTL_TEXTENCODING_ASCII_US );
-#endif
+        ByteString myHost( impl_getHostname() );
         if (aHost == myHost) {
             // lockfile by same UID
             OUString myUserName;
@@ -194,24 +211,7 @@ namespace desktop {
         aConfig.SetGroup(Group());
 
         // get information
-        ByteString aHost;
-#ifdef WNT
-        /*
-          prevent windows from connecting to the net to get it's own
-          hostname by using the netbios name
-        */
-        sal_Int32 sz = MAX_COMPUTERNAME_LENGTH + 1;
-        char* szHost = new char[sz];
-        if (GetComputerName(szHost, (LPDWORD)&sz))
-            aHost = OString(szHost);
-        else
-            aHost = OString("UNKNOWN");
-        delete[] szHost;
-#else
-        oslSocketResult sRes;
-        aHost  = OUStringToOString(
-            SocketAddr::getLocalHostname( &sRes ), RTL_TEXTENCODING_ASCII_US );
-#endif
+        ByteString aHost( impl_getHostname() );
         OUString aUserName;
         Security aSecurity;
         aSecurity.getUserName( aUserName );


More information about the Libreoffice-commits mailing list