summaryrefslogtreecommitdiff
path: root/desktop/source/app/lockfile.cxx
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2010-10-15 11:37:46 +0200
committerJan Holesovsky <kendy@suse.cz>2010-10-15 11:40:35 +0200
commite739fe0869ed4bb26615def73d83e055145148e8 (patch)
tree447117be2bb2bb25ba4fd4b8a6b6b48a547f4551 /desktop/source/app/lockfile.cxx
parent59e48cc7e19dcf1181bf24239ac0604f79f44014 (diff)
Don't do dns lookup on startup.
lockfile-dont-do-dns-lookup.diff, n#389257
Diffstat (limited to 'desktop/source/app/lockfile.cxx')
-rw-r--r--desktop/source/app/lockfile.cxx72
1 files changed, 36 insertions, 36 deletions
diff --git a/desktop/source/app/lockfile.cxx b/desktop/source/app/lockfile.cxx
index 7803074b45..514aa65d0b 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 );